Skip to content

fix(network): stop HTTP and WebSocket requests after old version error - #6897

Open
SeniorZhai wants to merge 1 commit into
masterfrom
fix/stop-requests-on-old-version
Open

SeniorZhai wants to merge 1 commit into
masterfrom
fix/stop-requests-on-old-version

Conversation

@SeniorZhai

Copy link
Copy Markdown
Member

No description provided.

@gaotic

gaotic Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

AI review done for 4e3a165 in 23m 28s · 5 comments

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.

Role Model Status
Reviewer GPT codex/gpt-6.2-sol · effort high ok
Reviewer Grok grok/grok-4.7@500k · effort medium ok
Summary codex/gpt-6.2-sol · effort medium ok

@gaotic gaotic Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant