Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Sources/JavaScriptEventLoop/JobQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ extension JavaScriptEventLoop {

func runAllJobs() {
assert(queueState.isSpinning)
// `defer`, so the latch is released even if a job throws.
//
// `runSynchronously` can unwind — a Swift runtime trap, or (under
// JavaScriptKit specifically) a JS exception crossing back into wasm.
// Clearing `isSpinning` only by falling off the end of the loop leaves
// it latched `true` on that path, and `insertJobQueue` then never
// schedules another drain: the executor is dead for the lifetime of the
// process, silently.
defer { queueState.isSpinning = false }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think for such scenarios where an unwind happens outside of Swift's throws mechanism, the defer block won't be executed, so I don't think this change solves the issue?


while let job = self.claimNextFromQueue() {
#if compiler(>=5.9)
Expand All @@ -50,8 +59,6 @@ extension JavaScriptEventLoop {
job._runSynchronously(on: self.asUnownedSerialExecutor())
#endif
}

queueState.isSpinning = false
}

func claimNextFromQueue() -> UnownedJob? {
Expand Down