url: fix logic in connection reuse to deny reuse on "unclean" connections

- add parameter to `conn_is_alive()` cfilter method that returns
  if there is input data waiting on the connection
- refrain from re-using connnection from the cache that have
  input pending
- adapt http/2 and http/3 alive checks to digest pending input
  to check the connection state
- remove check_cxn method from openssl as that was just doing
  what the socket filter now does.
- add tests for connection reuse with special server configs

Closes #10690
This commit is contained in:
Stefan Eissing 2023-03-06 12:44:45 +01:00 committed by Daniel Stenberg
parent 6466071e8e
commit 7c5637b8b4
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
17 changed files with 264 additions and 190 deletions

View file

@ -325,20 +325,6 @@ int Curl_socket_close(struct Curl_easy *data, struct connectdata *conn,
return socket_close(data, conn, FALSE, sock);
}
bool Curl_socket_is_dead(curl_socket_t sock)
{
int sval;
bool ret_val = TRUE;
sval = SOCKET_READABLE(sock, 0);
if(sval == 0)
/* timeout */
ret_val = FALSE;
return ret_val;
}
#ifdef USE_WINSOCK
/* When you run a program that uses the Windows Sockets API, you may
experience slow performance when you copy data to a TCP server.
@ -1449,12 +1435,14 @@ static CURLcode cf_socket_cntrl(struct Curl_cfilter *cf,
}
static bool cf_socket_conn_is_alive(struct Curl_cfilter *cf,
struct Curl_easy *data)
struct Curl_easy *data,
bool *input_pending)
{
struct cf_socket_ctx *ctx = cf->ctx;
struct pollfd pfd[1];
int r;
*input_pending = FALSE;
(void)data;
if(!ctx || ctx->sock == CURL_SOCKET_BAD)
return FALSE;
@ -1479,6 +1467,7 @@ static bool cf_socket_conn_is_alive(struct Curl_cfilter *cf,
}
DEBUGF(LOG_CF(data, cf, "is_alive: valid events, looks alive"));
*input_pending = TRUE;
return TRUE;
}