Skip to content

Don't send (in)active when channel closes directly#3497

Merged
Lukasa merged 10 commits intoapple:mainfrom
josephnoir:no-events-on-direct-close
Feb 11, 2026
Merged

Don't send (in)active when channel closes directly#3497
Lukasa merged 10 commits intoapple:mainfrom
josephnoir:no-events-on-direct-close

Conversation

@josephnoir
Copy link
Copy Markdown
Contributor

@josephnoir josephnoir commented Jan 28, 2026

Motivation

Issue #2773 reports a problem where channels can receive channelInactive before channelActive. This breaks expectations and should not happen. Instead of sending them in the wrong order, this PR suppresses both of them in those cases.

Modifications

  • Add a test to reproduce the problematic behavior.
  • Update the state machine to split the active state into two. This decouples succeeding the promise from sending the signal. Transiting to closing only sends channelInactive when originating from the state that sent channelActive.

Result

Address #2773.

Edit: Updated modifications to reflect latests commit.

Motivation:

Issue apple#2773 reports a series of events where channels can receive
channelInactive before channelActive. This breaks expectations and
should not happen. Instead of sending them in the wrong order, this
PR suppresses both of them.

Modifications:

* Add a test to reproduce the problematic behavior.
* Add a new flag to track if channelActive was fired.
* Check if the state machine is still in the active state before firing
  channelActive.

Result:

Address apple#2773.
@josephnoir josephnoir marked this pull request as draft January 28, 2026 11:09
@josephnoir josephnoir added the 🔨 semver/patch No public API change. label Jan 28, 2026
@josephnoir josephnoir marked this pull request as ready for review January 29, 2026 10:16
case (.preActivation, .finishActivation):
self.currentState = .fullyActivated
return { promise, pipeline in
promise?.succeed(())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In cases where we expect no promises to arrive, let's just assert there isn't one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, sounds good.

Copy link
Copy Markdown
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Very nice, thanks @josephnoir!

@Lukasa Lukasa merged commit d948192 into apple:main Feb 11, 2026
54 of 55 checks passed
@josephnoir josephnoir deleted the no-events-on-direct-close branch February 11, 2026 17:03
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.

2 participants