Repository navigation
fix(network): stop HTTP and WebSocket requests after old version error - #6897
SeniorZhai wants to merge 1 commit into
Conversation
|
AI review done for Quality: Needs fixes before merge. The change affects message durability and shutdown across several clients, and verification covered the affected call paths and focused Kotlin checks on the JVM.
|
There was a problem hiding this comment.
AI review · GPT + Grok · 4e3a165
Request changes. git diff --check passed, and focused Kotlin checks reproduced the callback race and confirmed retry classification. The offline Gradle run stopped during settings configuration because the Foojay resolver plugin was unavailable, so Android assembly, lint, and unit tests did not run.
| } else { | ||
| if (blazeMessage.error.code == OLD_VERSION) { | ||
| if (transactions[blazeMessage.id] != null) { | ||
| transactions[blazeMessage.id]!!.error.error(blazeMessage) |
There was a problem hiding this comment.
If HTTP and Blaze both return OLD_VERSION, HTTP shutdown can clear transactions between these two lookups. The !! then throws in the receive coroutine and reaches the process-wide crash handler. Remove the transaction atomically and invoke the callback on the returned value. Use the same pattern for the other response branches, which can race with the same shutdown.
| } | ||
| runCatching { | ||
| getJobManager().apply { | ||
| cancelAllJob() |
There was a problem hiding this comment.
This can orphan an outgoing message when Blaze rejects an in-flight send with OLD_VERSION. The callback releases the send job, then cancelAllJob() can mark it cancelled before deliver() throws. JobQueue drops the persistent job when retry is declined, and onCancel() leaves the message at SENDING. Pause sends for the version block and preserve their queued jobs so they can resume after an upgrade.
| runCatching { | ||
| val networkRuntime = getNetworkRuntime() | ||
| networkRuntime.getChatWebSocket().disconnect() | ||
| networkRuntime.getOkHttpClient().dispatcher.cancelAll() |
There was a problem hiding this comment.
This cancels only the primary client's dispatcher. Route, Referral, Cash, and Earn each have their own dispatcher, so a call already past its version guard can continue after shutdown, including POST web3/swap. Cancel calls on all four dispatchers as part of the same transition.
| // Interceptor | ||
| builder.addInterceptor { chain -> | ||
| if (MixinApplication.get().isOldVersion()) { | ||
| throw ClientErrorException(OLD_VERSION) |
There was a problem hiding this comment.
BaseJob.shouldRetry() treats this exception as a retryable IOException, so a persistent job such as RefreshAccountJob can repeatedly hit this guard. After a process restart, JobQueue starts running when injected, while the restored version flag skips the one-time stop(). Keep the queue paused while the persisted block is active and handle this exception explicitly before the generic IOException branch.
| defaultSharedPreferences.putInt(Constants.Account.PREF_OLD_VERSION_CODE, BuildConfig.VERSION_CODE) | ||
| if (firstTrigger) { | ||
| stopNetworkWorkForOldVersion() | ||
| InitializeActivity.showOldVersionAlert(this) |
There was a problem hiding this comment.
Android can silently deny this one-time activity launch when Blaze reports OLD_VERSION in the background with no app task available. The block still persists, but the only foreground fallback is MainActivity.onCreate(). A direct entry such as the share target can open without showing the update screen. Check the block when an app activity comes to the foreground and present the alert there if needed.
No description provided.