Skip to content

Commit ee13f17

Browse files
committed
Fix #170: Preventing remove the new reader/writer by the old one
1 parent 0edf33b commit ee13f17

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

uvloop/loop.pyx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,6 +2277,12 @@ cdef class Loop:
22772277
if self._debug and sock.gettimeout() != 0:
22782278
raise ValueError("the socket must be non-blocking")
22792279

2280+
# Remove the callback early. It should be rare that the
2281+
# selector says the fd is ready but the call still returns
2282+
# EAGAIN, and I am willing to take a hit in that case in
2283+
# order to simplify the common case.
2284+
self._remove_reader(sock)
2285+
22802286
fut = self._new_reader_future(sock)
22812287
handle = new_MethodHandle3(
22822288
self,
@@ -2303,6 +2309,12 @@ cdef class Loop:
23032309
if self._debug and sock.gettimeout() != 0:
23042310
raise ValueError("the socket must be non-blocking")
23052311

2312+
# Remove the callback early. It should be rare that the
2313+
# selector says the fd is ready but the call still returns
2314+
# EAGAIN, and I am willing to take a hit in that case in
2315+
# order to simplify the common case.
2316+
self._remove_reader(sock)
2317+
23062318
fut = self._new_reader_future(sock)
23072319
handle = new_MethodHandle3(
23082320
self,
@@ -2354,6 +2366,12 @@ cdef class Loop:
23542366
data = memoryview(data)
23552367
data = data[n:]
23562368

2369+
# Remove the callback early. It should be rare that the
2370+
# selector says the fd is ready but the call still returns
2371+
# EAGAIN, and I am willing to take a hit in that case in
2372+
# order to simplify the common case.
2373+
self._remove_writer(sock)
2374+
23572375
fut = self._new_writer_future(sock)
23582376
handle = new_MethodHandle3(
23592377
self,
@@ -2384,6 +2402,12 @@ cdef class Loop:
23842402
if self._debug and sock.gettimeout() != 0:
23852403
raise ValueError("the socket must be non-blocking")
23862404

2405+
# Remove the callback early. It should be rare that the
2406+
# selector says the fd is ready but the call still returns
2407+
# EAGAIN, and I am willing to take a hit in that case in
2408+
# order to simplify the common case.
2409+
self._remove_reader(sock)
2410+
23872411
fut = self._new_reader_future(sock)
23882412
handle = new_MethodHandle2(
23892413
self,

0 commit comments

Comments
 (0)