Skip to content

Commit 6bd03ac

Browse files
graingertclaude
andcommitted
Stop receiving when a UDPTransport handle is closed directly
UDPTransport keeps a reference to itself while receiving, which was only dropped by _stop_reading(). loop.close() closes leftover handles with _close(), so a UDP transport still open at that point was never freed. Stop reading in _close(), as UVStream does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent fd02ac3 commit 6bd03ac

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎uvloop/handles/udp.pxd‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ cdef class UDPTransport(UVBaseTransport):
1313
cdef open(self, int family, int sockfd)
1414
cdef _set_broadcast(self, bint on)
1515

16+
cdef _close(self)
17+
1618
cdef inline __receiving_started(self)
1719
cdef inline __receiving_stopped(self)
1820

‎uvloop/handles/udp.pyx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ cdef class UDPTransport(UVBaseTransport):
171171
else:
172172
self.__receiving_stopped()
173173

174+
cdef _close(self):
175+
try:
176+
# Drop the reference held while receiving, even when the
177+
# handle is closed directly (e.g. by loop.close()).
178+
self._stop_reading()
179+
finally:
180+
UVSocketHandle._close(<UVHandle>self)
181+
174182
cdef inline __receiving_started(self):
175183
if self.__receiving:
176184
return

0 commit comments

Comments
 (0)