Replace AndroidAsync WebSocket transport with OkHttp#254
Draft
mzorz wants to merge 1 commit into
Draft
Conversation
AndroidAsync is unmaintained (last release ~2022) and the source of intermittent transport crashes (e.g. the 'double connect callback' AssertionError during the SSL handshake). Swap the realtime WebSocket to OkHttp, which is actively maintained and already shipped by most host apps. - Add OkHttpWebSocketProvider implementing WebSocketManager.ConnectionProvider, mapping Connection/ConnectionListener onto OkHttp's WebSocketListener. - Route a post-open onFailure through onDisconnect (OkHttp's terminal failure has no onClosed) so channels are notified, the heartbeat is cancelled, and a reconnect is scheduled — matching AndroidAsync. - Sanitize the session id sent as User-Agent (OkHttp validates header values strictly; AndroidAsync did not). - Wire AndroidClient.buildChannelProvider to the new provider; keep AsyncWebSocketProvider in the tree for now. Note: cert pinning is not yet ported to the OkHttp client (see TODO); must be addressed before merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replaces the realtime WebSocket transport from AndroidAsync (
com.koushikdutta.async:androidasync:3.1.0) to OkHttp.AndroidAsync is unmaintained (last release ~2022) and the source of intermittent transport crashes in the field — notably the
java.lang.AssertionError: double connect callbackduring the SSL handshake (AsyncHttpClient$3.onConnectCompleted). OkHttp is actively maintained and already a dependency of most host apps (Simplenote ships OkHttp 5.x), so this removes a dead dependency without adding real weight.Changes
OkHttpWebSocketProvider(new) — implementsWebSocketManager.ConnectionProvider, mappingConnection{close,send}/ConnectionListener{onConnect,onMessage,onDisconnect,onError}onto OkHttp'sWebSocketListener. OkHttp'ssend/closeare thread-safe, so it drops the main-looperHandlerhop the AndroidAsync provider needed.onFailurerouting — after a successful upgrade, OkHttp'sonFailureis a terminal disconnect (noonClosedfollows), so it's routed throughlistener.onDisconnect()(notifies channels, cancels the heartbeat, schedules reconnect), matching the AndroidAsync end/closed-callback behavior. A pre-open failure goes toonError.User-Agentsanitization — Simperium passes the session id as theUser-Agentheader; OkHttp validates header values strictly (AndroidAsync did not), so non-printable/non-ASCII chars are stripped.AndroidClient.buildChannelProviderswitched to the new provider.AsyncWebSocketProvideris kept in the tree for now (AndroidAsync is still used for the auth HTTP client).Validation
ConnectionProviderinterface (:Simperium:compileDebugJavaWithJavac).MockWebServerprobe), removing the AndroidAsync large-frame instability.Software caused connection abortdisconnects via the newonFailurerouting.Before merge (open items)
configureSSL()applies a customSSLContext+PinningTrustManagerto the AndroidAsyncmHttpClient. The newOkHttpClientis a plain client and does not replicate it. Port the pinning to the OkHttp builder (sslSocketFactory+X509TrustManager, orCertificatePinner) — or make a deliberate decision to drop the (ancient AndroidPinning 1.0.0) pinning. Flagged with a TODO inAndroidClient.Context
This came out of investigating large notes not syncing to Android (Simplenote SIMPL-58). That turned out to be a server-side object-size cap (the server returns
413 EXCEEDS_MAX_SIZE), not a transport bug — so this OkHttp swap is a maintenance/stability improvement, not the fix for that issue. It's worth doing on its own merits (kills the unmaintained, crash-prone transport).