Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exclusive access violation in NIOAsyncChannelOutboundWriterHandler #2580

Merged
merged 1 commit into from
Oct 27, 2023

Conversation

FranzBusch
Copy link
Member

Motivation

We were setting self.sink = nil in the NIOAsyncChannelOutboundWriterHandler twice in the same call stack which is an exclusivity violation. This happens because the first self.sink = nil triggers the didTerminate delegate call which again triggered self.sink = nil.

Modification

This PR changes the code to only call self.sink?.finish() and only sets the sink to nil in the didTerminate implementation. This follows what we do for the inbound handler implementation. I also added a test that triggers this exclusivity violation.

Result

No more exclusivity violations in our code.

# Motivation
We were setting `self.sink = nil` in the `NIOAsyncChannelOutboundWriterHandler` twice in the same call stack which is an exclusivity violation. This happens because the first `self.sink = nil` triggers the `didTerminate` delegate call which again triggered `self.sink = nil`.

# Modification
This PR changes the code to only call `self.sink?.finish()` and only sets the `sink` to `nil` in the `didTerminate` implementation. This follows what we do for the inbound handler implementation. I also added a test that triggers this exclusivity violation.

# Result
No more exclusivity violations in our code.
@FranzBusch FranzBusch added the semver/patch No public API change. label Oct 27, 2023
@FranzBusch FranzBusch enabled auto-merge (squash) October 27, 2023 15:26
@finagolfin
Copy link
Contributor

I can confirm this gets the NIO HTTP/2 tests passing again on linux x86_64.

@FranzBusch FranzBusch merged commit 9497e44 into apple:main Oct 27, 2023
8 checks passed
@FranzBusch FranzBusch deleted the fb-fix-exclusive-access-violation branch October 27, 2023 16:52
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.

3 participants