Skip to content

Fix for swift test : _Concurrency/Executor.swift:357: Fatal error#639

Merged
sebsto merged 2 commits intomainfrom
fix/concurrency_assertion_error
Feb 14, 2026
Merged

Fix for swift test : _Concurrency/Executor.swift:357: Fatal error#639
sebsto merged 2 commits intomainfrom
fix/concurrency_assertion_error

Conversation

@sebsto
Copy link
Collaborator

@sebsto sebsto commented Feb 12, 2026

Fix the issue described at #640

Here is the proposed fix:

I added a new function assumeIsolatedOnEventLoop — a nonisolated method that:

  1. Calls self.eventLoop.preconditionInEventLoop() to verify we're on the correct event loop (NIO's own thread-identity check, which always works)
  2. Uses unsafeBitCast to strip the isolated annotation, the same pattern NIO uses internally and that I found on the Swift Forums.

See: https://github.com/swiftlang/swift/blob/main/stdlib/public/Concurrency/ExecutorAssertions.swift#L348

See: https://forums.swift.org/t/actor-assumeisolated-erroneously-crashes-when-using-a-dispatch-queue-as-the-underlying-executor/72434/3

@sebsto sebsto added the 🔨 semver/patch No public API change. label Feb 12, 2026
@sebsto sebsto self-assigned this Feb 12, 2026
@sebsto sebsto requested a review from Copilot February 12, 2026 16:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes swift test crashes on open-source Swift 6.2.3 toolchains built with +assertions by avoiding Actor.assumeIsolated in NIO callback contexts where Swift Concurrency can’t validate the current executor.

Changes:

  • Add LambdaRuntimeClient.assumeIsolatedOnEventLoop, which validates isolation via eventLoop.preconditionInEventLoop() and then uses an unsafe cast to run an isolated closure.
  • Replace two assumeIsolated call sites (closeFuture.whenComplete and connectionWillClose) with assumeIsolatedOnEventLoop.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sebsto sebsto changed the title Fix fro swift test : _Concurrency/Executor.swift:357: Fatal error Fix for swift test : _Concurrency/Executor.swift:357: Fatal error Feb 12, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@sebsto sebsto requested a review from adam-fowler February 14, 2026 10:02
@sebsto
Copy link
Collaborator Author

sebsto commented Feb 14, 2026

@adam-fowler if time permits, can you have a look at this and tell me if it makes sense? I'd like to check if my understanding is correct and if the fix, borrowed from NIO's project, is safe. Thank you

Copy link
Collaborator

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adam-fowler if time permits, can you have a look at this and tell me if it makes sense? I'd like to check if my understanding is correct and if the fix, borrowed from NIO's project, is safe. Thank you

I've not seen this in valkey-swift and we use a similar setup with an actor running on the event loop. But code looks fine

@sebsto sebsto merged commit fef8c0d into main Feb 14, 2026
87 of 88 checks passed
@sebsto sebsto deleted the fix/concurrency_assertion_error branch February 14, 2026 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test suite fails on toolchain' sassertion : _Concurrency/Executor.swift:357: Fatal error

3 participants