Repository navigation
fix(ios): rebuild the listener after iOS takes a suspended app's sockets - #46
Merged
Merged
Conversation
iOS reclaims the sockets of an app it has suspended. A reclaimed listening socket keeps its descriptor, refuses every connection and never becomes readable, and nonblocking accept keeps reporting EAGAIN. The acceptor only watched for readability, so its sessions stream never ended, the SDK never reached the retry loop that binds a new listener, and Necto could not see the app again until it was relaunched. A listening socket is never writable until the kernel tears it down and reports EOF there. The acceptor now watches for that and ends its sessions stream with an error, which hands control to the existing retry loop. Nothing observes the app's lifecycle, so a listener that survived is left alone.
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.
Summary
After an iPhone is locked for a minute or two and the app is brought back to the foreground without relaunching, Necto no longer sees the app. Every port in the SDK's range refuses the connection while the app is alive and in the foreground, and only a relaunch brings it back.
iOS reclaims the sockets of an app it has suspended, the listening one included. The app is told nothing: the descriptor stays open, connections to its port are refused, the socket never becomes readable, and nonblocking
acceptkeeps reportingEAGAIN.NectoSocketAcceptoronly watched for readability, so itssessionsstream never ended, andNectoSDKRuntime.servenever returned to the retry loop that binds a new listener.A listening socket is never writable either, until the kernel tears it down and reports EOF there. The acceptor now holds a write source on the same descriptor and ends
sessionswith an error when it fires. The existing retry loop does the rest: a new listener a second later, found by the Mac's next probe..failedfor the second it takes to rebuild.NectoControlServeron the Mac uses the same acceptor and gains the same behaviour. A healthy listener, TCP or Unix, does not fire the write source.accept, which throws when the socket breaks, and its runtime already rebuilds after that.Changelog
iOS: Necto reconnects to an app that returns from suspension, without relaunching it.
Test Plan
script/test swiftTwo tests are new. Both use
disconnectxto tear a listening socket down while leaving its descriptor open, which leaves it in the state described above: connections refused, never readable,acceptreportingEAGAIN.a listening socket the system tore down ends the acceptor's sessions: with the fix reverted it runs into its time limit; with the fix it passes at once.listensAgainAfterTheSystemTakesItsSockets: with a session connected, tears down the listener and the accepted connection, then expects the runtime to report listening again and to accept a new connection.A one-off run on macOS that reclaimed the test process's sockets through
pid_shutdown_sockets, which is not part of the suite, gave the same sequence:connected,listening,failed, thenlisteningon a new port.On a physical iPhone over USB, with ExampleApp built from this branch:
necto device listshowed the app, the phone was locked, then unlocked and the app brought forward without relaunching. The app showed the failed status briefly and Necto connected to it again.Not run: the Android Gradle build, since nothing under
SDK/Androidchanged.