From: Daniel Stenberg Date: Mon, 4 Oct 2004 10:36:51 +0000 (+0000) Subject: Made the dns entry remain locked while a connection to the host remains to X-Git-Tag: curl-7_12_2~59 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=95def48071e54c769ee063ddf53f05c9595602d2;p=curl Made the dns entry remain locked while a connection to the host remains to allow verbose output during this period. Bertrand Demiddelaer reported and helped fixing. --- diff --git a/lib/easy.c b/lib/easy.c index 4782fc459..228d2aef0 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -391,11 +391,6 @@ void curl_easy_cleanup(CURL *curl) if(!data) return; - if ( ! (data->share && data->share->hostcache) ) { - if ( !Curl_global_host_cache_use(data)) { - Curl_hash_destroy(data->hostcache); - } - } Curl_close(data); } diff --git a/lib/hostip.c b/lib/hostip.c index f3aa36c6a..c9c78784f 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -263,8 +263,9 @@ void Curl_hostcache_prune(struct SessionHandle *data) { time_t now; - if(data->set.dns_cache_timeout == -1) - /* cache forever means never prune! */ + if((data->set.dns_cache_timeout == -1) || !data->hostcache) + /* cache forever means never prune, and NULL hostcache means + we can't do it */ return; if(data->share) @@ -459,7 +460,11 @@ int Curl_resolv(struct connectdata *conn, } } else { + if(data->share) + Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE); dns->inuse++; /* we use it! */ + if(data->share) + Curl_share_unlock(data, CURL_LOCK_DATA_DNS); rc = CURLRESOLV_RESOLVED; } diff --git a/lib/url.c b/lib/url.c index c0921ced4..9ac054a68 100644 --- a/lib/url.c +++ b/lib/url.c @@ -204,6 +204,12 @@ CURLcode Curl_close(struct SessionHandle *data) /* Loop through all open connections and kill them one by one */ while(-1 != ConnectionKillOne(data)); + if ( ! (data->share && data->share->hostcache) ) { + if ( !Curl_global_host_cache_use(data)) { + Curl_hash_destroy(data->hostcache); + } + } + #ifdef USE_SSLEAY /* Close down all open SSL info and sessions */ Curl_SSL_Close_All(data); @@ -1432,6 +1438,17 @@ CURLcode Curl_disconnect(struct connectdata *conn) data = conn->data; + if(conn->dns_entry) + Curl_resolv_unlock(data, conn->dns_entry); /* done with this */ + +#if defined(CURLDEBUG) && defined(AGGRESIVE_TEST) + /* scan for DNS cache entries still marked as in use */ + Curl_hash_apply(data->hostcache, + NULL, Curl_scan_cache_used); +#endif + + Curl_hostcache_prune(data); /* kill old DNS cache entries */ + /* * The range string is usually freed in curl_done(), but we might * get here *instead* if we fail prematurely. Thus we need to be able @@ -3230,8 +3247,7 @@ static CURLcode CreateConnection(struct SessionHandle *data, if(conn->bits.reuse) { /* re-used connection, no resolving is necessary */ hostaddr = NULL; - conn->dns_entry = NULL; /* we don't connect now so we don't have any fresh - dns entry struct to point to */ + /* we'll need to clear conn->dns_entry later in Curl_disconnect() */ if (conn->bits.httpproxy) fix_hostname(conn, &conn->host); @@ -3480,17 +3496,6 @@ CURLcode Curl_done(struct connectdata **connp, conn->newurl = NULL; } - if(conn->dns_entry) - Curl_resolv_unlock(conn->data, conn->dns_entry); /* done with this */ - -#if defined(CURLDEBUG) && defined(AGGRESIVE_TEST) - /* scan for DNS cache entries still marked as in use */ - Curl_hash_apply(data->hostcache, - NULL, Curl_scan_cache_used); -#endif - - Curl_hostcache_prune(data); /* kill old DNS cache entries */ - /* this calls the protocol-specific function pointer previously set */ if(conn->curl_done) result = conn->curl_done(conn, status); diff --git a/tests/data/test506 b/tests/data/test506 index d43ac91d3..7b76a9575 100644 --- a/tests/data/test506 +++ b/tests/data/test506 @@ -79,11 +79,11 @@ unlock: cookie : 11 lock: cookie : 12 unlock: cookie : 13 run 1: set cookie 1, 2 and 3 +CLEANUP lock: dns : 14 unlock: dns : 15 lock: dns : 16 unlock: dns : 17 -CLEANUP lock: cookie : 18 unlock: cookie : 19 *** run 2 @@ -93,49 +93,53 @@ unlock: share : 21 PERFORM lock: dns : 22 unlock: dns : 23 -lock: cookie : 24 -unlock: cookie : 25 +lock: dns : 24 +unlock: dns : 25 lock: cookie : 26 unlock: cookie : 27 lock: cookie : 28 unlock: cookie : 29 +lock: cookie : 30 +unlock: cookie : 31 run 2: set cookie 4 and 5 -lock: dns : 30 -unlock: dns : 31 +CLEANUP lock: dns : 32 unlock: dns : 33 -CLEANUP -lock: cookie : 34 -unlock: cookie : 35 +lock: dns : 34 +unlock: dns : 35 +lock: cookie : 36 +unlock: cookie : 37 *** run 3 CURLOPT_SHARE -lock: share : 36 -unlock: share : 37 +lock: share : 38 +unlock: share : 39 CURLOPT_COOKIEJAR PERFORM -lock: dns : 38 -unlock: dns : 39 -lock: cookie : 40 -unlock: cookie : 41 -lock: cookie : 42 -unlock: cookie : 43 +lock: dns : 40 +unlock: dns : 41 +lock: dns : 42 +unlock: dns : 43 lock: cookie : 44 unlock: cookie : 45 +lock: cookie : 46 +unlock: cookie : 47 +lock: cookie : 48 +unlock: cookie : 49 run 3: overwrite cookie 1 and 4 -lock: dns : 46 -unlock: dns : 47 -lock: dns : 48 -unlock: dns : 49 try SHARE_CLEANUP... lock: share : 50 unlock: share : 51 SHARE_CLEANUP failed, correct CLEANUP -lock: cookie : 52 -unlock: cookie : 53 +lock: dns : 52 +unlock: dns : 53 +lock: dns : 54 +unlock: dns : 55 +lock: cookie : 56 +unlock: cookie : 57 SHARE_CLEANUP -lock: share : 54 -unlock: share : 55 +lock: share : 58 +unlock: share : 59 GLOBAL_CLEANUP