Skip to content

Fix: iOS cache server not recovering after background suspension - #19

Merged
Colton127 merged 2 commits into
mainfrom
fix/ios-keepAlive-recovery
Sep 24, 2026
Merged

Colton127 merged 2 commits into
mainfrom
fix/ios-keepAlive-recovery

Conversation

@Colton127

Copy link
Copy Markdown
Owner

On iOS, the local server's listening socket can be reclaimed while the app is suspended. The health check was meant to recover it, but ensureActive() bound the new server before closing the old one. A shared bind to a port that's still open in the same process reuses the existing socket, so every recovery attempt reattached to the dead socket and the server never came back (-1004 "could not connect to server").

Changes

  • Fix: close the old server first, then bind a fresh socket on the same port. It closes without force, so requests already in progress aren't cut off.
  • New: HttpCacheManager.ensureActive(), so apps can make sure the server is accepting connections before retrying a cache URL that failed to connect (e.g. playback resumed from Control Center before the next health check).
  • Bump to 0.2.1; changelog and README updated.

Tests

  • New keep_alive_server_test.dart checks that a rebind replaces the kernel socket (via lsof; skipped where lsof isn't available). It fails against the old order.
  • New ensureActive() tests for the manager.

A shared HttpServer.bind to an (address, port) that is still open in the
same process reuses the existing listening socket. ensureActive() bound the
replacement before closing the old server, so after iOS reclaimed the socket
during suspension every recovery attempt re-attached to the same dead socket
and the server stayed unreachable.

Close the old server first, then bind a fresh socket. Closing without force
leaves in-flight requests untouched. Bump to 0.2.1.
Exposes the local server's health check so apps can make sure the server is
accepting connections before retrying a cache URL request that failed to
connect. The periodic iOS health check cannot close the gap when a player
connects immediately after the app resumes from background suspension.
@Colton127
Colton127 merged commit db7db87 into main Sep 24, 2026
2 checks passed
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