Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mback2k
Copy link
Member

@mback2k mback2k commented Jun 3, 2020

The select-based socket check correctly checks for connect
failures by adding the write socket also to fds_err.

The poll-based implementation (which internally can itself
fallback to select again) did not previously check for
connect failure by using POLLPRI with the write socket.

This commit makes sure connect failures can be detected
and handled if HAVE_POLL_FINE is defined, eg. on msys2-devel.
Therefore the related disabled tests can be enabled again.

Related to #5492

@mback2k mback2k requested a review from bagder June 3, 2020 07:04
@mback2k mback2k self-assigned this Jun 3, 2020
@mback2k mback2k marked this pull request as draft June 6, 2020 07:11
@mback2k mback2k added feature-window A merge of this requires an open feature window on-hold and removed feature-window A merge of this requires an open feature window labels Jun 6, 2020
@mback2k
Copy link
Member Author

mback2k commented Jun 6, 2020

I still need to investigate the exact circumstances of the underlying issue a little bit more first, therefore this PR is back to Draft state and put on hold.

The select-based socket check correctly checks for connect
failures by adding the write socket also to fds_err.

The poll-based implementation (which internally can itself
fallback to select again) did not previously check for
connect failure by using POLLPRI with the write socket.

This commit makes sure connect failures can be detected
and handled if HAVE_POLL_FINE is defined, eg. on msys2-devel.
Therefore the related disabled tests can be enabled again.

Related to curl#5492
@mback2k mback2k force-pushed the fix-poll-connect-failure branch from d7edc80 to 7767bc4 Compare June 6, 2020 19:39
@mback2k
Copy link
Member Author

mback2k commented Jun 8, 2020

Note to myself: May also be related to #5542.

@mback2k mback2k added the feature-window A merge of this requires an open feature window label Jun 18, 2020
@bagder
Copy link
Member

bagder commented Jun 23, 2020

A note on the commit message. It just says what doesn't work (and sounds like a bug report), it doesn't really explain what change this commit brings...

@mback2k
Copy link
Member Author

mback2k commented Jun 24, 2020

it doesn't really explain what change this commit brings...

It doesn't? I think this does:

The poll-based implementation (which internally can itself
fallback to select again) did not previously check for
connect failure by using POLLPRI with the write socket.

It basically adds checking for POLLPRI which can be inferred from this statement.

But anyway, I am still investigating this for the next feature window. This fix is required with #5492, but still does not make curl on msys2-runtime detect connect timeouts properly. But I guess this is more like a msys2-runtime issue which I am trying to confirm.

@mback2k
Copy link
Member Author

mback2k commented Jul 14, 2020

But anyway, I am still investigating this for the next feature window. This fix is required with #5492, but still does not make curl on msys2-runtime detect connect timeouts properly. But I guess this is more like a msys2-runtime issue which I am trying to confirm.

I finally found the root cause of the issue that curl is not able to detect connection reset/timeout on msys2-runtime/Cygwin-fork. The problem also exist in original Cygwin and can easily reproduced with a simple curl 127.0.0.1:47 (connect to non-listening local port) even inside Cygwin.

Curl calls poll twice during easy_transfer, first time in curl_multi_poll and a second time curl_multi_perform. Unfortunately msys2-runtime and Cygwin implement poll using a select-wrapper around WSAEnumNetworkEvents seemingly without handling the fact that FD_CLOSE is only given/returned once for a socket.

Per wait-loop iteration the first call to poll in curl_multi_poll could get the notification about the connection being closed, but it does not check for the socket being writable/exceptional and also cannot handle that situation. Then the second call to poll in curl_multi_perform actually does check for the condition, but will never get the notification, because it was already consumed during the first call to poll.

I guess msys2-runtime/Cygwin could be changed to internally keep track of having seen the FD_CLOSE event, just like they already handle seen shutdown calls. For now I see no possible workaround on our site, because their poll and select are both affected, this means a fallback or pre-check with select like implemented in #5634 or sockfilt.c is not possible.

So I will now continue with this PR and #5492 soon and also report this runtime issue upstream to Cygwin and msys2.

@mback2k
Copy link
Member Author

mback2k commented Jul 15, 2020

... also report this runtime issue upstream to Cygwin and msys2.

Patch posted to Cygwin mailing list: https://cygwin.com/pipermail/cygwin/2020-July/245528.html

@mback2k
Copy link
Member Author

mback2k commented Jul 21, 2020

One part of this issue has been fixed in Cygwin now. The part relevant to #5492 will now be fixed as part of #5707.

@mback2k mback2k closed this Jul 21, 2020
mback2k added a commit to mback2k/curl that referenced this pull request Aug 1, 2020
This commit changes Curl_socket_check to use POLLPRI to
check for connect failure on the write socket, because
POLLPRI maps to fds_err. This is in line with select(2).

The select-based socket check correctly checks for connect
failures by adding the write socket also to fds_err.

The poll-based implementation (which internally can itself
fallback to select again) did not previously check for
connect failure by using POLLPRI with the write socket.

See the follow up commit to this for more information.

This commit makes sure connect failures can be detected
and handled if HAVE_POLL_FINE is defined, eg. on msys2-devel.

Replaces curl#5509
Related to curl#5492
Part of curl#5707
mback2k added a commit to mback2k/curl that referenced this pull request Aug 1, 2020
Change Curl_socket_check to use select-fallback in Curl_poll
instead of implementing it in Curl_socket_check and Curl_poll.

Replaces curl#5262 and curl#5492
Follow up to curl#5509
Closes curl#5707
mback2k added a commit that referenced this pull request Aug 25, 2020
This commit changes Curl_socket_check to use POLLPRI to
check for connect failure on the write socket, because
POLLPRI maps to fds_err. This is in line with select(2).

The select-based socket check correctly checks for connect
failures by adding the write socket also to fds_err.

The poll-based implementation (which internally can itself
fallback to select again) did not previously check for
connect failure by using POLLPRI with the write socket.

See the follow up commit to this for more information.

This commit makes sure connect failures can be detected
and handled if HAVE_POLL_FINE is defined, eg. on msys2-devel.

Reviewed-by: Daniel Stenberg
Reviewed-by: Jay Satiro

Replaces #5509
Prepares #5707
@mback2k
Copy link
Member Author

mback2k commented Aug 25, 2020

The patch for Cygwin has now made it into a new release: https://www.mail-archive.com/[email protected]/msg09303.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

connecting & proxies feature-window A merge of this requires an open feature window on-hold regression

Development

Successfully merging this pull request may close these issues.

2 participants