signalapp / libsignal-service-java

A Java/Android library for communicating with the Signal messaging service.
GNU General Public License v3.0
587 stars 271 forks source link

let KeepAliveSender detect if websocket is no longer alive - fixes #6447 (non GCM) #49

Open rkohrt opened 6 years ago

rkohrt commented 6 years ago

let KeepAliveSender detect if the websocket is no longer alive and trigger recreation of SignalServiceMessagePipe - fixes WhisperSystems/Signal-Android#6447 for non GCM devices

By not checking for the response of the keep alive message it is not detected when the device goes from mobile -> WiFi or vice versa. Thus we keep sending the keep alive message to a broken pipe over and over for no reason. While we will not get push messages from the server, because we do not have a working active connection to it. I fixed the problem by listening for 30seconds to the future (line 298) created by sending the keep alive message and if we do not get a response within these 30 seconds, the connection is killed -> WebSocketConnection.client = null -> WebSocketConnection.readRequest will throw IOException("Connection closed!") -> SignalServiceMessageReceiver.MessageRetrievalThread.run will catch it and create a new SignalServiceMessagePipe utilizing the new network and we keep subscribed for push messages :-)

rkohrt commented 6 years ago

Any comments on this one? I don't think I am the only one that has problems with this bug.