Skip to content

SocketAsyncContext.Unix: fix double processing of AsyncOperations - #45683

Merged
geoffkizer merged 2 commits into
dotnet:masterfrom
tmds:socket_process
Dec 15, 2020
Merged

SocketAsyncContext.Unix: fix double processing of AsyncOperations#45683
geoffkizer merged 2 commits into
dotnet:masterfrom
tmds:socket_process

Conversation

@tmds

@tmds tmds commented Dec 7, 2020

Copy link
Copy Markdown
Member

When a socket event occurs, the pending operations gets triggered
to continue their work by calling the Process method.

The changes in #37974
cause Process to be called twice on the same AsyncOperation.

When Process is called, the operation can complete, and the
AsyncOperation instance may be reused for a different operation.

Fixes #45673

cc @geoffkizer @karelz @antonfirsov @stephentoub @dotnet/ncl

@ghost

ghost commented Dec 7, 2020

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

When a socket event occurs, the pending operations gets triggered
to continue their work by calling the Process method.

The changes in #37974
cause Process to be called twice on the same AsyncOperation.

When Process is called, the operation can complete, and the
AsyncOperation instance may be reused for a different operation.

Fixes #45673

cc @geoffkizer @karelz @antonfirsov @stephentoub @dotnet/ncl

Author: tmds
Assignees: -
Labels:

area-System.Net.Sockets

Milestone: -

@stephentoub

Copy link
Copy Markdown
Member

Thanks. We need to service for this as well, right? Seems like this could lead to really inconsistent and bad behaviors?

@tmds

tmds commented Dec 7, 2020

Copy link
Copy Markdown
Member Author

Thanks. We need to service for this as well, right? Seems like this could lead to really inconsistent and bad behaviors?

Yes, I also think we need to service this.
In some cases the locks and state prevent this from becoming a problem, but that's not true in general.

@geoffkizer I'm glad you noticed this. Figuring it out from a product bug report would have been a real challenge.

@wfurt wfurt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@geoffkizer

Copy link
Copy Markdown
Contributor

As a minimal fix this seems fine.

That said, I don't think we need the processAsyncEvents parameter at all. Instead we could just return the operation to the caller to decide how to process it. That seems like it would eliminate the confusion over who should process the event -- it should always be the caller, for async events.

tmds added 2 commits December 10, 2020 09:09
When a socket event occurs, the pending operations gets triggered
to continue their work by calling the Process method.

The changes in dotnet#37974
cause Process to be called twice on the same AsyncOperation.

When Process is called, the operation can complete, and the
AsyncOperation instance may be reused for a different operation.
@karelz

karelz commented Dec 15, 2020

Copy link
Copy Markdown
Member

@geoffkizer can you please review the updated changes?

@geoffkizer
geoffkizer merged commit 87ff54b into dotnet:master Dec 15, 2020
@geoffkizer

Copy link
Copy Markdown
Contributor

@tmds To clarify the impact of this issue...

I don't think an operation will ever be processed twice because of this issue, right? The logic in ProcessSyncEventOrGetAsyncEvent will return null if the op is processed, so the caller will not process it again.

What will happen though is that the operation is always processed directly on the calling thread, as opposed to the logic in HandleEvents where we will dispatch one of the operations to the thread pool for processing if we have two operations to process. This seems like enough of a reason to backport it, as it could cause unexpected and mysterious delays in processing the second operation. But I don't think it's any worse than that, is it?

@tmds

tmds commented Dec 15, 2020

Copy link
Copy Markdown
Member Author

@geoffkizer that's right, and it's a lot less worse than I thought.

antonfirsov added a commit to antonfirsov/runtime that referenced this pull request Jan 8, 2021
…tnet#45683)

* SocketAsyncContext.Unix: fix double processing of AsyncOperations

When a socket event occurs, the pending operations gets triggered
to continue their work by calling the Process method.

The changes in dotnet#37974
cause Process to be called twice on the same AsyncOperation.

When Process is called, the operation can complete, and the
AsyncOperation instance may be reused for a different operation.

* Remove processAsyncEvents
@ghost ghost locked as resolved and limited conversation to collaborators Jan 14, 2021
@karelz karelz added this to the 6.0.0 milestone Jan 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[.NET 5 regression] Socket.AsyncOperation gets processed too many times

6 participants