Merge pull request 'Close a connection if sending fails.' (#438) from send into master
continuous-integration/drone/push Build is pending Details

Reviewed-on: #438
Reviewed-by: Dan Ballard <dan@openprivacy.ca>
This commit is contained in:
Sarah Jamie Lewis 2022-03-29 19:16:47 +00:00
commit 3fbf88d34b
1 changed files with 15 additions and 1 deletions

View File

@ -153,7 +153,21 @@ func (pa *PeerApp) SendMessage(message model2.PeerMessage) error {
}
if err == nil {
return pa.connection.Send(serialized)
err = pa.connection.Send(serialized)
// at this point we have tried to send a message to a peer only to find that something went wrong.
// we don't know *what* went wrong - the most likely explanation is the peer went offline in the time between
// sending the message and it arriving in the engine to be sent. Other explanations include problems with Tor,
// a dropped wifi connection.
// Regardless, we error out this message and close this peer app assuming it cannot be used again.
// We expect that cwtch will eventually recreate this connection and the app.
if err != nil {
// close any associated sockets
pa.connection.Close()
// tell cwtch this connection is no longer valid
pa.OnClose(err.Error())
}
return err
}
return err
}