Skip to content

Fix race conditions and delayed connections - #50

Merged
atdrendel merged 4 commits into
mainfrom
fix-race-condition
Apr 6, 2026
Merged

Fix race conditions and delayed connections#50
atdrendel merged 4 commits into
mainfrom
fix-race-condition

Conversation

@atdrendel

Copy link
Copy Markdown
Contributor
  • Fix race conditions where a Task was created and thus started before the Task it was replacing had been cancelled
  • Speed up PhoenixSocket.connect() by correctly resetting reconnection state in both disconnect() and connect()

Copilot AI review requested due to automatic review settings April 6, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses reconnection/flush task race conditions in the Phoenix client and reduces delayed reconnect behavior by ensuring prior tasks/continuations are properly cancelled before starting replacements.

Changes:

  • Add PushBuffer.cancelAwaitingContinuation() and cancel prior timeout tasks when updating the next timeout.
  • Fix PhoenixSocket task replacement races (flush/listen/heartbeat/reconnect) and reset reconnection state when connecting/disconnecting during a reconnect loop.
  • Add regression tests for cancelling an awaiting iterator and for reconnect-loop behavior around disconnect()/connect().

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Tests/PhoenixTests/PushBufferTests.swift Adds tests for cancelling an awaiting iterator and ensuring a new iterator can proceed afterward.
Tests/PhoenixTests/PhoenixSocketTests.swift Adds tests ensuring disconnect() stops reconnect loops and connect() after disconnect during reconnect has no backoff.
Sources/Phoenix/PushBuffer.swift Adds continuation cancellation helper and fixes timeout task replacement by cancelling the previous task.
Sources/Phoenix/PhoenixSocket.swift Cancels/replaces stored tasks safely, resets reconnect state on connect/disconnect, and improves cancellation handling in doConnect().
Package.swift Raises minimum supported platform versions.
.github/workflows/ci.yml Updates CI runner and hard-pins an Xcode app bundle path.

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

@shareup shareup deleted a comment from Copilot AI Apr 6, 2026
@atdrendel
atdrendel merged commit 5834c14 into main Apr 6, 2026
5 checks passed
@atdrendel
atdrendel deleted the fix-race-condition branch April 6, 2026 16:37
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.

2 participants