Connection paused before closing to avoid EBADF error