From 1242f366249b086424924f56a052ab64bae57659 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Thu, 21 May 2020 22:45:48 -0700 Subject: [PATCH] tolerate data arriving briefly after we hang up If the file receiver hangs up on an established connection, we do a `transport.loseConnection()` on the buddy (the file sender). But apparently it takes a moment (perhaps a roundtrip through the kernel) for the incoming data to stop, and that used to cause an error. In May 2020 this happened 11 times in 40 days. Now we just ignore this late data. --- src/wormhole_transit_relay/transit_server.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/wormhole_transit_relay/transit_server.py b/src/wormhole_transit_relay/transit_server.py index fd287fc..1c7f0e2 100644 --- a/src/wormhole_transit_relay/transit_server.py +++ b/src/wormhole_transit_relay/transit_server.py @@ -56,6 +56,14 @@ class TransitConnection(protocol.Protocol): # practice, this buffers about 10MB per connection, after which # point the sender will only transmit data as fast as the # receiver can handle it. + if not self._buddy: + # Our buddy disconnected (we're "jilted"), so we hung up too, + # but our incoming data hasn't stopped yet (it will in a + # moment, after our disconnect makes a roundtrip through the + # kernel). This probably means the file receiver hung up, and + # this connection is the file sender. In may-2020 this + # happened 11 times in 40 days. + return self._total_sent += len(data) self._buddy.transport.write(data) return