Skip to content

Commit f24c2c5

Browse files
jlaine1st1
authored andcommitted
Don't use non-existent UDPTransport._address attribute (fixes: #207)
If the sendto() method is called after closing the transport, it bombs with an AttributeError as there is no `._address` attribute. Replacing this by `.address` is not a solution either, as we need to exit in any case otherwise the call to sendto() bombs again due to `.sock` having been set to None.
1 parent d5ad2b8 commit f24c2c5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

tests/test_udp.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,19 @@ def test_udp_sendto_dns(self):
201201
s_transport.close()
202202
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
203203

204+
def test_send_after_close(self):
205+
coro = self.loop.create_datagram_endpoint(
206+
asyncio.DatagramProtocol,
207+
local_addr=('127.0.0.1', 0),
208+
family=socket.AF_INET)
209+
210+
s_transport, _ = self.loop.run_until_complete(coro)
211+
212+
s_transport.close()
213+
s_transport.sendto(b'aaaa', ('127.0.0.1', 80))
214+
self.loop.run_until_complete(asyncio.sleep(0.01, loop=self.loop))
215+
s_transport.sendto(b'aaaa', ('127.0.0.1', 80))
216+
204217

205218
class Test_AIO_UDP(_TestUDP, tb.AIOTestCase):
206219
pass

uvloop/handles/udp.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ cdef class UDPTransport(UVBaseTransport):
165165
validate_address(addr, self.sock_family, self.sock_type,
166166
self.sock_proto)
167167

168-
if self._conn_lost and self._address:
168+
if self._conn_lost:
169169
if self._conn_lost >= LOG_THRESHOLD_FOR_CONNLOST_WRITES:
170170
aio_logger.warning('socket.send() raised exception.')
171171
self._conn_lost += 1

0 commit comments

Comments
 (0)