[Proposal] remove lock from SocketAsyncEngine#36115
[Proposal] remove lock from SocketAsyncEngine#36115adamsitnik wants to merge 6 commits intodotnet:masterfrom
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. |
|
|
||
| private void AddToMap(SocketAsyncContext context) | ||
| { | ||
| IntPtr socketFileDescriptor = context.GetSocketFileDescriptor(); |
There was a problem hiding this comment.
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.
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
SocketAsyncEngineby doing two things:n) engines: the first async call is going to createnengines (andnepolls)IntPtrs, 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