mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 12:38:33 +00:00
Cancel chatConnectionFuture when we get disconnect() while CONNECTING.
This commit is contained in:
@@ -240,13 +240,10 @@ class LibSignalChatConnection(
|
|||||||
// OkHttpWebSocketConnection will terminate a connection if disconnect() is called while
|
// OkHttpWebSocketConnection will terminate a connection if disconnect() is called while
|
||||||
// the connection itself is still CONNECTING, so we carry forward that behavior here.
|
// the connection itself is still CONNECTING, so we carry forward that behavior here.
|
||||||
if (state.value == WebSocketConnectionState.CONNECTING) {
|
if (state.value == WebSocketConnectionState.CONNECTING) {
|
||||||
// The right way to do this is to cancel the CompletableFuture returned by connectChat().
|
Log.i(TAG, "$name Cancelling connection attempt...")
|
||||||
// This will terminate forward progress on the connection attempt, and mostly closely match
|
// This is safe because we just checked that state == CONNECTING
|
||||||
// what OkHttpWebSocketConnection does.
|
chatConnectionFuture!!.cancel(true)
|
||||||
// Unfortunately, libsignal's CompletableFuture does not yet support cancellation.
|
state.onNext(WebSocketConnectionState.DISCONNECTED)
|
||||||
// So, instead, we set a flag to disconnect() as soon as the connection completes.
|
|
||||||
// TODO [andrew]: Add cancellation support to CompletableFuture and use it here
|
|
||||||
state.onNext(WebSocketConnectionState.DISCONNECTING)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user