-
Notifications
You must be signed in to change notification settings - Fork 523
Don't post to closed socket (CI Fix) #337
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.AspNet.Server.Kestrel.Networking | ||
|
@@ -199,6 +200,9 @@ public void async_init(UvLoopHandle loop, UvAsyncHandle handle, uv_async_cb cb) | |
protected Func<UvAsyncHandle, int> _uv_async_send; | ||
public void async_send(UvAsyncHandle handle) | ||
{ | ||
// Can't Assert with .Validate as that checks threadId | ||
// and this function is to post to correct thread. | ||
Debug.Assert(!handle.IsInvalid, "Handle is invalid"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this was intended to prevent AVs, it could only have any affect on debug builds. I don't think even Trace.Assert would save us from the AVs we've been seeing. This might be nice to have, but I doubt this fixes any bugs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helped me track down the bug; only needed for debug. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you put just this change in and run ./build in Windows; debug when the Assert pops up you can clearly see what's going on. |
||
Check(_uv_async_send(handle)); | ||
} | ||
|
||
|
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.
Is this meant to be a perf optimization?
_thread.Post
shouldn't fail because the socket is closed.We only actually use
_socket
in theWriteContext
methods where_socket.IsClosed
is always checked first thing.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.
The issue is the loop is the gone hence all the calls erroring are actually
uv_async_send
so its post that fails. However the socket has been successfully closed on the server; so a check to see if the socket is closed fixes it; rather than checking if the loop is valid.It occurs when
socketShutdownSend
has happened; the client closes the socket, the server picks this up and then the close is kicked off; so when there is a slight delay betweensocketShutdownSend
andsocketDisconnect
while the loop has terminated because its been asked to and all the sockets are closed.Its potentially only in a full shutdown scenarios (e.g. the tests or controlled app recycle)
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.
It might be better to expose something from KestrelThread so that callers know?
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 think its only in a shutdown race situation; happens in both windows and mono. When it happens windows seems ok with it, but mono very unhappy.
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.
for example
OnWriteCompleted
calls it after it acquires the lock as doesWrite
after doing a bunch of stuffThere 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.
Will mitigate this in a later PR; but this will stop the AV for now.