Skip to content

Fix network requests hanging after app is backgrounded and reopened - #3733

Open
mzaki9 wants to merge 1 commit into
mihonapp:mainfrom
mzaki9:fix/stale-connections
Open

Fix network requests hanging after app is backgrounded and reopened#3733
mzaki9 wants to merge 1 commit into
mihonapp:mainfrom
mzaki9:fix/stale-connections

Conversation

@mzaki9

@mzaki9 mzaki9 commented Aug 10, 2026

Copy link
Copy Markdown

After backgrounding the app and reopening it, network requests sometimes hang forever (manga pages keep spinning) until the app is force-stopped. This is the known OkHttp stale-connection issue: idle keep-alive connections in the connection pool die while the app is backgrounded (WiFi power-save, radio recycling, network switches) and requests routed to them hang silently until the 5-minute idle reap. With DNS-over-HTTPS enabled, the DoH resolver client builds its own client via build(), so it has a second, separate pool that nothing ever evicts.

Changes:

  • Share a single ConnectionPool between the main client and the DoH resolver client (set on the builder before the DoH provider block), so one evictAll() clears both pools.
  • Evict the pool on network transitions (internet lost/regained) via a NetworkCallback registered with registerDefaultNetworkCallback.
  • Evict the pool when the app returns to the foreground (ProcessLifecycleOwner ON_START).

Testing:

  1. Open a manga, background the app, toggle WiFi or let the device sleep, reopen.
  2. Manga pages load without force-stopping the app.

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