-
Notifications
You must be signed in to change notification settings - Fork 656
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
Call NIOAsyncWriterSinkDelegate
outside of the lock
#2547
Call NIOAsyncWriterSinkDelegate
outside of the lock
#2547
Conversation
delegate: delegate | ||
) | ||
|
||
return .callDidYield(delegate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens to sequence
in this branch? It looks like we just ignore it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see where the confusion is coming from. We are just yielding it to the delegate right away when we return callDidYield
. The caller of this method still has the sequence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, gotcha, thanks for clarifying.
# Motivation The current `NIOAsyncWriter` implementation expects that the delegate is called while holding the lock to avoid reentrancy issues. However, this prevents us from executing the delegate calls directly on the `EventLoop` if we are on it already. # Modification This moves all of the delegate calls outside of the locks and adds protection against reentrancy into the state machine. # Result Less allocations. Clarify the reentrancy problems in docs and protect against them in the writer
cde1274
to
378e01f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice improvement.
Motivation
The current
NIOAsyncWriter
implementation expects that the delegate is called while holding the lock to avoid reentrancy issues. However, this prevents us from executing the delegate calls directly on theEventLoop
if we are on it already.Modification
This moves all of the delegate calls outside of the locks and adds protection against reentrancy into the state machine.
Result
Less allocations.