Skip to content

fix: prevent NPE crash from OkHttp executor shutdown race#217

Merged
barrydeen merged 1 commit intomainfrom
fix/okhttp-shutdown-race
Mar 11, 2026
Merged

fix: prevent NPE crash from OkHttp executor shutdown race#217
barrydeen merged 1 commit intomainfrom
fix/okhttp-shutdown-race

Conversation

@barrydeen
Copy link
Copy Markdown
Owner

Summary

  • Add safeShutdownClient() helper to HttpClientFactory that cancels in-flight calls, evicts connections, and awaits executor termination before shutdown — preventing NPE when OkHttp threads are still processing WebSocket close frames
  • Replace raw shutdown() + evictAll() calls in RelayProber (2 locations) with the safe helper
  • Fix leaked OkHttpClient in RelayPool.swapClientAndReconnect() by cleaning up the old client after creating the new one

Test plan

  • Build and install on device
  • Trigger relay probing (onboarding or relay settings) — no NPE crashes in logcat
  • Toggle Tor on/off to exercise swapClientAndReconnect() — no thread leaks or crashes

Cancel in-flight calls and await executor termination before shutdown
to prevent NullPointerException when OkHttp threads are still processing
WebSocket close frames. Also fixes leaked OkHttpClient in
swapClientAndReconnect().
@barrydeen barrydeen merged commit 1e3ddcc into main Mar 11, 2026
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