connection: terminate after goaway

When a multiplex connection (h2/h3) is shutdown by the server, the
reported number of parallel transfers allowed drops to 0.

Determine that when the last transfer is done and terminate the
connection instead of keeping it in the cache.

We detect the drop to 0 also when we try to reuse such a connection, but
if we know this at the time the last transfer is done, we better
terminate it right away.

Have a consistent trace logging to this with the connections current
hostname and port. Adjust test expectations to carry port numbers.

Closes #17884
This commit is contained in:
Stefan Eissing 2025-07-10 12:16:40 +02:00 committed by Daniel Stenberg
parent 2ec54556d4
commit b453a447ce
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
8 changed files with 58 additions and 42 deletions

View file

@ -535,6 +535,22 @@ static void multi_done_locked(struct connectdata *conn,
void *userdata)
{
struct multi_done_ctx *mdctx = userdata;
#ifndef CURL_DISABLE_VERBOSE_STRINGS
const char *host =
#ifndef CURL_DISABLE_PROXY
conn->bits.socksproxy ?
conn->socks_proxy.host.dispname :
conn->bits.httpproxy ? conn->http_proxy.host.dispname :
#endif
conn->bits.conn_to_host ? conn->conn_to_host.dispname :
conn->host.dispname;
int port =
#ifndef CURL_DISABLE_PROXY
conn->bits.httpproxy ? conn->http_proxy.port :
#endif
conn->bits.conn_to_port ? conn->conn_to_port :
conn->remote_port;
#endif
Curl_detach_connection(data);
@ -580,30 +596,27 @@ static void multi_done_locked(struct connectdata *conn,
#endif
) || conn->bits.close
|| (mdctx->premature && !Curl_conn_is_multiplex(conn, FIRSTSOCKET))) {
CURL_TRC_M(data, "multi_done, not reusing connection=%"
FMT_OFF_T ", forbid=%d"
", close=%d, premature=%d, conn_multiplex=%d",
conn->connection_id, data->set.reuse_forbid,
conn->bits.close, mdctx->premature,
Curl_conn_is_multiplex(conn, FIRSTSOCKET));
CURL_TRC_M(data, "multi_done, terminating conn #%" FMT_OFF_T " to %s:%d, "
"forbid=%d, close=%d, premature=%d, conn_multiplex=%d",
conn->connection_id, host, port, data->set.reuse_forbid,
conn->bits.close, mdctx->premature,
Curl_conn_is_multiplex(conn, FIRSTSOCKET));
connclose(conn, "disconnecting");
Curl_conn_terminate(data, conn, mdctx->premature);
}
else if(!Curl_conn_get_max_concurrent(data, conn, FIRSTSOCKET)) {
CURL_TRC_M(data, "multi_done, conn #%" FMT_OFF_T " to %s:%d was shutdown"
" by server, not reusing", conn->connection_id, host, port);
connclose(conn, "server shutdown");
Curl_conn_terminate(data, conn, mdctx->premature);
}
else {
/* the connection is no longer in use by any transfer */
if(Curl_cpool_conn_now_idle(data, conn)) {
/* connection kept in the cpool */
const char *host =
#ifndef CURL_DISABLE_PROXY
conn->bits.socksproxy ?
conn->socks_proxy.host.dispname :
conn->bits.httpproxy ? conn->http_proxy.host.dispname :
#endif
conn->bits.conn_to_host ? conn->conn_to_host.dispname :
conn->host.dispname;
data->state.lastconnect_id = conn->connection_id;
infof(data, "Connection #%" FMT_OFF_T " to host %s left intact",
conn->connection_id, host);
infof(data, "Connection #%" FMT_OFF_T " to host %s:%d left intact",
conn->connection_id, host, port);
}
else {
/* connection was removed from the cpool and destroyed. */