-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[Proposal] remove lock from SocketAsyncEngine #36115
Conversation
Tagging subscribers to this area: @dotnet/ncl |
|
I was wondering about that too after #36019. I was chatting with @stephentoub about it, and I think another way to resolve 5e64fa3 would be to check socket readability before reading SO_ERROR for connect completion. |
@@ -289,6 +169,24 @@ private SocketAsyncEngine() | |||
} | |||
} | |||
|
|||
private void AddToMap(SocketAsyncContext context) | |||
{ | |||
IntPtr socketFileDescriptor = context.GetSocketFileDescriptor(); |
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.
This is using DangerousGetHandle
which may cause issues (besides 5e64fa3) due to fd recycling.
@stephentoub @tmds thanks for providing the additional context. This makes me wonder why simply don't remove given socket from To my understanding we are just adding to |
That happens automatically in the kernel. The race happens when the |
…ull engine remove from dictionary first, then remove from epoll
error = Interop.Sys.TryChangeSocketEventRegistration(_port, socket, | ||
Interop.Sys.SocketEvents.Read | Interop.Sys.SocketEvents.Write, | ||
Interop.Sys.SocketEvents.None, socket.DangerousGetHandle()); | ||
return error == Interop.Error.SUCCESS; |
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.
This happens automagically in the kernel when the socket is closed. And it doesn't solve the race issue between the epoll thread and the thread that creates/closes sockets. See #36115 (comment).
…queue notification can be handled as soon as we receive it if registration fails, remove context from the map remove context from the map to make sure that we stop handling notifications first
@tmds thanks for all the great insights. I am going to close it for now and most probably send a simplified version later this week (just removing lock, not removing the id system) |
While working on #36019 I've noticed that we could simplify the
SocketAsyncEngine
by doing two things:n
) engines: the first async call is going to createn
engines (andn
epolls)IntPtr
s, and avoid lock when adding new context to the engine.I don't know why we are generating new ids instead of using existing socket file descriptors (there was probably a good reason for that), so this is just a proposal.
/cc @tmds @stephentoub