From 7fd53a3b165fc0df944788c4b98ad237b4b30f07 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 29 Mar 2022 11:35:50 -0700 Subject: [PATCH 1/2] Close a connection is sending fails. --- protocol/connections/peerapp.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/protocol/connections/peerapp.go b/protocol/connections/peerapp.go index bfc2c3e..c4d9f03 100644 --- a/protocol/connections/peerapp.go +++ b/protocol/connections/peerapp.go @@ -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 connection 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 } From a39775d56b0866fc3210139e213e57884dbfa6c5 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Tue, 29 Mar 2022 12:15:33 -0700 Subject: [PATCH 2/2] connection -> message --- protocol/connections/peerapp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol/connections/peerapp.go b/protocol/connections/peerapp.go index c4d9f03..17ace0c 100644 --- a/protocol/connections/peerapp.go +++ b/protocol/connections/peerapp.go @@ -155,7 +155,7 @@ func (pa *PeerApp) SendMessage(message model2.PeerMessage) error { if err == nil { err = pa.connection.Send(serialized) - // at this point we have tried to send a connection to a peer only to find that something went wrong. + // 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.