cancel callLater on error or timeout

This commit is contained in:
Jack Robison 2018-02-20 13:42:49 -05:00
parent df78f7ff9f
commit b4bc5e2110
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2

View file

@ -173,6 +173,13 @@ class KademliaProtocol(protocol.DatagramProtocol):
# Transmit the data
self._send(encodedMsg, msg.id, (contact.address, contact.port))
self._sentMessages[msg.id] = (contact.id, df, timeoutCall, method, args)
def cancel(err):
if timeoutCall.cancelled or timeoutCall.called:
return err
timeoutCall.cancel()
df.addErrback(cancel)
return df
def startProtocol(self):
@ -336,7 +343,8 @@ class KademliaProtocol(protocol.DatagramProtocol):
self._call_later_list[key] = delayed_call
def _write_and_remove(self, key, txData, address):
del self._call_later_list[key]
if key in self._call_later_list:
del self._call_later_list[key]
if self.transport:
try:
self.transport.write(txData, address)