select: return error from "lethal" poll/select errors

Adds two new error codes: CURLE_UNRECOVERABLE_POLL and
CURLM_UNRECOVERABLE_POLL one each for the easy and the multi interfaces.

Reported-by: Harry Sintonen
Fixes #8921
Closes #8961
This commit is contained in:
Daniel Stenberg 2022-06-08 11:03:07 +02:00
parent 7007324a6a
commit 5912da253b
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
10 changed files with 37 additions and 8 deletions

View file

@ -306,7 +306,7 @@ int Curl_resolver_getsock(struct Curl_easy *data,
* 2) wait for the timeout period to check for action on ares' sockets.
* 3) tell ares to act on all the sockets marked as "with action"
*
* return number of sockets it worked on
* return number of sockets it worked on, or -1 on error
*/
static int waitperform(struct Curl_easy *data, timediff_t timeout_ms)
@ -338,8 +338,11 @@ static int waitperform(struct Curl_easy *data, timediff_t timeout_ms)
break;
}
if(num)
if(num) {
nfds = Curl_poll(pfd, num, timeout_ms);
if(nfds < 0)
return -1;
}
else
nfds = 0;
@ -376,7 +379,8 @@ CURLcode Curl_resolver_is_resolved(struct Curl_easy *data,
DEBUGASSERT(dns);
*dns = NULL;
waitperform(data, 0);
if(waitperform(data, 0) < 0)
return CURLE_UNRECOVERABLE_POLL;
#ifndef HAVE_CARES_GETADDRINFO
/* Now that we've checked for any last minute results above, see if there are
@ -475,7 +479,8 @@ CURLcode Curl_resolver_wait_resolv(struct Curl_easy *data,
else
timeout_ms = 1000;
waitperform(data, timeout_ms);
if(waitperform(data, timeout_ms) < 0)
return CURLE_UNRECOVERABLE_POLL;
result = Curl_resolver_is_resolved(data, entry);
if(result || data->state.async.done)

View file

@ -549,6 +549,8 @@ static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
/* wait for activity or timeout */
pollrc = Curl_poll(fds, numfds, ev->ms);
if(pollrc < 0)
return CURLE_UNRECOVERABLE_POLL;
after = Curl_now();

View file

@ -1312,6 +1312,8 @@ static CURLMcode multi_wait(struct Curl_multi *multi,
#else
pollrc = Curl_poll(ufds, nfds, timeout_ms); /* wait... */
#endif
if(pollrc < 0)
return CURLM_UNRECOVERABLE_POLL;
if(pollrc > 0) {
retcode = pollrc;

View file

@ -352,8 +352,12 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, timediff_t timeout_ms)
value).
*/
r = our_select(maxfd, &fds_read, &fds_write, &fds_err, timeout_ms);
if(r <= 0)
if(r <= 0) {
if((r == -1) && (SOCKERRNO == EINTR))
/* make EINTR from select or poll not a "lethal" error */
r = 0;
return r;
}
r = 0;
for(i = 0; i < nfds; i++) {

View file

@ -317,6 +317,9 @@ curl_easy_strerror(CURLcode error)
case CURLE_SSL_CLIENTCERT:
return "SSL Client Certificate required";
case CURLE_UNRECOVERABLE_POLL:
return "Unrecoverable error in select/poll";
/* error codes not used by current libcurl */
case CURLE_OBSOLETE20:
case CURLE_OBSOLETE24:
@ -400,6 +403,9 @@ curl_multi_strerror(CURLMcode error)
case CURLM_ABORTED_BY_CALLBACK:
return "Operation was aborted by an application callback";
case CURLM_UNRECOVERABLE_POLL:
return "Unrecoverable error in select/poll";
case CURLM_LAST:
break;
}