diff --git a/.changes/serial-cancellation b/.changes/serial-cancellation new file mode 100644 index 000000000..f6efb63c7 --- /dev/null +++ b/.changes/serial-cancellation @@ -0,0 +1 @@ +patch type="fixed" "Serial operations cancellation semantics" \ No newline at end of file diff --git a/Sources/LiveKit/Support/SerialRunnerActor.swift b/Sources/LiveKit/Support/SerialRunnerActor.swift index 40f88f121..398fbd86e 100644 --- a/Sources/LiveKit/Support/SerialRunnerActor.swift +++ b/Sources/LiveKit/Support/SerialRunnerActor.swift @@ -21,8 +21,8 @@ actor SerialRunnerActor { func run(block: @Sendable @escaping () async throws -> Value) async throws -> Value { let task = Task { [previousTask] in - // Wait for the previous task to complete, but cancel it if needed - if let previousTask, !Task.isCancelled { + // Always wait for the previous task to maintain serial ordering + if let previousTask { // If previous task is still running, wait for it _ = try? await previousTask.value }