Skip to content

Don't fatalError if NIOTypedHTTPServerUpgraderStateMachine is in state finished when finding upgrader#3597

Merged
Lukasa merged 4 commits into
apple:mainfrom
adam-fowler:finding-upgrader-close
May 21, 2026
Merged

Don't fatalError if NIOTypedHTTPServerUpgraderStateMachine is in state finished when finding upgrader#3597
Lukasa merged 4 commits into
apple:mainfrom
adam-fowler:finding-upgrader-close

Conversation

@adam-fowler
Copy link
Copy Markdown
Contributor

Don't fatalError in NIOTypedHTTPServerUpgraderStateMachine.findingUpgraderCompletedwhen the state is.finished`.

Motivation:

There is a race where the connection can be closed and the NIOTypedHTTPServerUpgraderHandler can be removed setting the state to .finished while we are still finding upgraders. And then when findingUpgraderCompleted gets called it would fatalError.

Modifications:

  • Return nil as an action if the state is .finished when findingUpgraderCompleted is called.
  • Added a new set of tests which test the NIOTypedHTTPServerUpgraderStateMachine directly instead of relying on HTTPServerUpgraderTests. I used Swift Testing for these, not sure what NIO policy on new tests are?

Result:

No more crashes and better testing for NIOTypedHTTPServerUpgraderStateMachine

The statemachine can be in the state finished because the connection was closed.
I also added a series of tests directly testing the upgrader statemachine
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.

Excellent stuff, thanks so much @adam-fowler

@Lukasa Lukasa added the 🔨 semver/patch No public API change. label May 14, 2026
@Lukasa
Copy link
Copy Markdown
Contributor

Lukasa commented May 14, 2026

Looks like a little tweak is needed.

@adam-fowler
Copy link
Copy Markdown
Contributor Author

@Lukasa

@adam-fowler adam-fowler requested a review from Lukasa May 20, 2026 15:25
@Lukasa Lukasa enabled auto-merge (squash) May 21, 2026 13:30
@Lukasa Lukasa merged commit 9670fe1 into apple:main May 21, 2026
51 of 54 checks passed
@adam-fowler adam-fowler deleted the finding-upgrader-close branch May 21, 2026 14:58
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