Skip to content
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

Fixes the call to setsockopt(SO_UPDATE_ACCEPT_CONTEXT) on Windows (#1598) #1604

Merged

Conversation

L0PiTaL
Copy link
Contributor

@L0PiTaL L0PiTaL commented Jul 13, 2022

From the docs, this function requires as a parameter the listener socket, not a boolean value.
With this change, shutdown now can start the socket closing process correctly.

fixes #1598

@L0PiTaL L0PiTaL force-pushed the fix-deadlock-when-CancelIoEx-fails branch from 0e0d33f to e588f9d Compare July 13, 2022 19:39
@@ -260,7 +260,13 @@ tcp_close(void *arg)
if (!c->closed) {
c->closed = true;
if (!nni_list_empty(&c->recv_aios)) {
CancelIoEx((HANDLE) c->s, &c->recv_io.olpd);
Copy link
Contributor

Choose a reason for hiding this comment

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

So the problem is that closing the socket didn't up the waiting receivers? Is that the situation? (A similar problem exists with UNIX and there some unfortunate workarounds for it in the POSIX side of the code.)

Copy link
Contributor Author

@L0PiTaL L0PiTaL Jul 14, 2022

Choose a reason for hiding this comment

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

@gdamore

FINALLY!
After your comment about closing the socket, I have checked the result of shutdown() and it also was raising an error (WSAENOTCONN).

After searching this error, it came from an issue on the call to setsockopt(SOL_SOCKET, SO_UPDATE_ACCEPT_CONTEXT) after AcceptEx.

From the docs, this function requires as a parameter the listener socket, not a boolean value.

Now it closes the connections correctly.

I have rebased this PR with these new changes, so it should be ready for review.

Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent. Strange behavior in Windows around this, but clearly what I had was a bug.

From the Windows docs, this option must receive as parameters the listener socket.
@L0PiTaL L0PiTaL force-pushed the fix-deadlock-when-CancelIoEx-fails branch from e588f9d to 2adb27e Compare July 14, 2022 12:50
@L0PiTaL L0PiTaL changed the title fixes infinite wait when CancelIoEx fails (#1598) Fixes the call to setsockopt(SO_UPDATE_ACCEPT_CONTEXT) on Windows (#1598) Jul 14, 2022
@L0PiTaL L0PiTaL requested a review from gdamore July 14, 2022 16:20
@gdamore gdamore merged commit b428d51 into nanomsg:master Jul 15, 2022
@L0PiTaL L0PiTaL deleted the fix-deadlock-when-CancelIoEx-fails branch July 25, 2022 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http_server deadlocks on shutdown
2 participants