Skip to content

Fix future issue in sock_connect() #391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions uvloop/loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ cdef class Loop:

if UVLOOP_DEBUG:
if fut.cancelled():
# Shouldn't happen with _SyncSocketReaderFuture.
# Shouldn't happen with _SyncSocketWriterFuture.
raise RuntimeError(
f'_sock_sendall is called on a cancelled Future')

Expand Down Expand Up @@ -1044,9 +1044,7 @@ cdef class Loop:
else:
return

fut = self._new_future()
fut.add_done_callback(lambda fut: self._remove_writer(sock))

fut = _SyncSocketWriterFuture(sock, self)
handle = new_MethodHandle3(
self,
"Loop._sock_connect",
Expand All @@ -1059,8 +1057,16 @@ cdef class Loop:
return fut

cdef _sock_connect_cb(self, fut, sock, address):
if fut.cancelled():
return
if UVLOOP_DEBUG:
if fut.cancelled():
# Shouldn't happen with _SyncSocketWriterFuture.
raise RuntimeError(
f'_sock_connect_cb is called on a cancelled Future')

if not self._has_writer(sock):
raise RuntimeError(
f'socket {sock!r} does not have a writer '
f'in the _sock_connect_cb callback')

try:
err = sock.getsockopt(uv.SOL_SOCKET, uv.SO_ERROR)
Expand All @@ -1074,8 +1080,10 @@ cdef class Loop:
raise
except BaseException as exc:
fut.set_exception(exc)
self._remove_writer(sock)
else:
fut.set_result(None)
self._remove_writer(sock)

cdef _sock_set_reuseport(self, int fd):
cdef:
Expand Down