Skip to content

Commit

Permalink
maybe send ack works needs a running trasport
Browse files Browse the repository at this point in the history
This fixes a regression, a context switch was introduced after the check
for the state of the datagram server, this context switch exposed a race
that allowed a call to `transport.send` on a closed transport.
  • Loading branch information
hackaugusto authored and LefterisJP committed Sep 4, 2017
1 parent d971887 commit 3624466
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 10 additions & 1 deletion raiden/network/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,17 @@ def _maybe_send_ack(self, receiver_address, messagedata):
""" ACK must not go into the queue, otherwise nodes will deadlock
waiting for the confirmation.
"""
host_port = self.get_host_port(receiver_address)

# ACKs are sent at the end of the receive method, after the message is
# sucessfully processed. It may be the case that the server is stopped
# after the message is received but before the ack is sent, under that
# circumstance the udp socket would be unavaiable and then an exception
# is raised.
#
# This check verifies the udp socket is still available before trying
# to send the ack. There must be *no context-switches after this test*.
if self.transport.server.started:
host_port = self.get_host_port(receiver_address)
self.transport.send(
self.raiden,
host_port,
Expand Down
3 changes: 3 additions & 0 deletions raiden/network/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def send(self, sender, host_port, bytes_):
if sleep_timeout:
gevent.sleep(sleep_timeout)

if not hasattr(self.server, 'socket'):
raise RuntimeError('trying to send a message on a closed server')

self.server.sendto(bytes_, host_port)

# enable debugging using the DummyNetwork callbacks
Expand Down

0 comments on commit 3624466

Please sign in to comment.