Fix: iOS cache server not recovering after background suspension - #19
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. Asharedbind 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
force, so requests already in progress aren't cut off.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).Tests
keep_alive_server_test.dartchecks that a rebind replaces the kernel socket (vialsof; skipped wherelsofisn't available). It fails against the old order.ensureActive()tests for the manager.