From 0360dab08c169af507680a510d65537019045a05 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Mon, 8 Feb 2021 16:07:04 -0500 Subject: [PATCH 1/2] Fix future issue in sock_connect() CPython fixed the same issue in python/cpython#10419. Seems like under pressure, more write callbacks may happen before _remove_writer() is called, so we should check for done(). Fixes #378 --- uvloop/loop.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx index 9ebf3a63..3ebc6588 100644 --- a/uvloop/loop.pyx +++ b/uvloop/loop.pyx @@ -1059,7 +1059,8 @@ cdef class Loop: return fut cdef _sock_connect_cb(self, fut, sock, address): - if fut.cancelled(): + if fut.done(): + # Refs #378: this may be called multiple times. return try: From cd856621ff0455f304188e3ceb9c5588ded098d3 Mon Sep 17 00:00:00 2001 From: Fantix King Date: Mon, 8 Feb 2021 19:38:46 -0500 Subject: [PATCH 2/2] Fix comments --- uvloop/loop.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx index 3ebc6588..f14e3a36 100644 --- a/uvloop/loop.pyx +++ b/uvloop/loop.pyx @@ -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')