dns_entry: move from conn to data->state

The `struct Curl_dns_entry *` used to established a connection
do not have the connection's lifetime, but the transfer's lifetime
(of the transfer that initiates the connect).

`Curl_dns_entry *` is reference counted with the "dns cache". That
cache might be owned by the multi or the transfer's share. In the
share, the reference count needs updating under lock.

Therefore, the dns entry can only be kept *and* released using the
same transfer it was initially looked up from. But a connection is
often discarded using another transfer.

So far, the problem of this has been avoided in clearing the connection's
dns entries in the "multi_don()" handling. So, connections had NULL
dns entries after the initial transfers and its connect had been handled.

Keeping the dns entries in data->state seems therefore a better choice.

Also: remove the `struct Curl_dns_entry *` from the connect filters
contexts. Use `data->state.dns` every time instead and fail correctly
when not present and needed.

Closes #17383
This commit is contained in:
Stefan Eissing 2025-05-19 12:25:58 +02:00 committed by Daniel Stenberg
parent 3ec6aa5c07
commit be45e014c6
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
14 changed files with 132 additions and 119 deletions

View file

@ -521,8 +521,8 @@ static void multi_done_locked(struct connectdata *conn,
data->state.done = TRUE; /* called just now! */
data->state.recent_conn_id = conn->connection_id;
if(conn->dns_entry)
Curl_resolv_unlink(data, &conn->dns_entry); /* done with this */
Curl_resolv_unlink(data, &data->state.dns[0]); /* done with this */
Curl_resolv_unlink(data, &data->state.dns[1]);
Curl_dnscache_prune(data);
/* if data->set.reuse_forbid is TRUE, it means the libcurl client has
@ -2165,7 +2165,7 @@ static CURLMcode state_resolving(struct Curl_multi *multi,
bool connected;
/* Perform the next step in the connection phase, and then move on to the
WAITCONNECT state */
result = Curl_once_resolved(data, &connected);
result = Curl_once_resolved(data, dns, &connected);
if(result)
/* if Curl_once_resolved() returns failure, the connection struct is