Skip to content

Resume the reachability probe's continuation only once - #1863

Open
kisnner26 wants to merge 1 commit into
altstoreio:classicfrom
kisnner26:fix/reachability-double-resume
Open

kisnner26 wants to merge 1 commit into
altstoreio:classicfrom
kisnner26:fix/reachability-double-resume

Conversation

@kisnner26

Copy link
Copy Markdown

fixes #1850

OnDeviceClient.isReachable() resumes a CheckedContinuation from the NWConnection state update handler. it clears the handler before resuming, but that doesn't guarantee a single resume: network can already have another state change queued (for example .waiting followed right away by .failed) that still reaches the closure, and resuming twice traps with a continuation misuse error.

the crash log in #1850 is that trap: CheckedContinuation.resume(returning:) calling _assertionFailure, on the io.altstore.reachability-probe queue.

this guards finish() with a one-shot flag (OSAllocatedUnfairLock), so only the first result is used. nothing else changes: the first result is handled exactly as before.

validation:

  • the file parses (swiftc -parse).
  • a standalone program with the same pattern and two finish calls already queued: without the flag it aborts with "tried to resume its continuation more than once" (exit 133, sigtrap); with the flag it finishes normally.

not validated:

  • i could not reproduce NWConnection firing two states in a row. i ran the same probe code against unreachable hosts, 240 probes with and without the flag on macos, and neither version crashed, so this is a defensive fix for the trap in the report, not a confirmed root cause of why the handler is called twice on ios 27.2.
  • i could not build the full ios app on this branch: ldid in AltSign doesn't find openssl's headers in my setup. the same construct (OSAllocatedUnfairLock.withLock inside a @Sendable local function) compiles on its own.

OnDeviceClient.isReachable() resumes a CheckedContinuation from the
NWConnection state update handler. Clearing the handler before resuming isn't
enough to guarantee a single resume: Network can already have another state
change queued (for example .waiting followed by .failed) that still reaches the
closure, and resuming twice traps with a continuation misuse error.

Guard finish() with a one-shot flag so only the first result is used.

Fixes altstoreio#1850
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