aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2006-02-16 23:42:32 +0000
committerDaniel Stenberg <daniel@haxx.se>2006-02-16 23:42:32 +0000
commit92009181af0c4c5608b7e7378e2ea21806ee5e33 (patch)
tree039a2c2dc845e985400fcde8823160ab87da3af0
parent831bdb9f6340f6f47623d7be1f10a2198e6a3774 (diff)
Shmulik Regev provided a fix for the DNS cache when using short life times,
as previously it could be holding on to old cached entries longer than requested.
-rw-r--r--CHANGES13
-rw-r--r--RELEASE-NOTES3
-rw-r--r--TODO-RELEASE2
-rw-r--r--lib/hostip.c40
4 files changed, 50 insertions, 8 deletions
diff --git a/CHANGES b/CHANGES
index 826b02100..cde84d33e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,11 +6,16 @@
Changelog
+Daniel (17 February 2006)
+- Shmulik Regev provided a fix for the DNS cache when using short life times,
+ as previously it could be holding on to old cached entries longer than
+ requested.
+
Daniel (11 February 2006)
-- Karl M added the CURLOPT_CONNECT_ONLY and CURLINFO_LASTSOCKET options that
- an app can use to let libcurl only connect to a remote host and then extract
- the socket from libcurl. libcurl will then not attempt to do any transfer at
- all after the connect is done.
+- Karl Moerder added the CURLOPT_CONNECT_ONLY and CURLINFO_LASTSOCKET options
+ that an app can use to let libcurl only connect to a remote host and then
+ extract the socket from libcurl. libcurl will then not attempt to do any
+ transfer at all after the connect is done.
- Kent Boortz improved the configure check for GnuTLS to properly set LIBS
instead of LDFLAGS.
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index 5cd89a464..4b73a2f60 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -21,6 +21,7 @@ This release includes the following changes:
This release includes the following bugfixes:
+ o cached DNS entries could remain in the cache too long
o improved GnuTLS check in configure
o re-used FTP connections when the second request didn't do a transfer
o plain --limit-rate [num] means bytes
@@ -62,6 +63,6 @@ advice from friends like these:
Dov Murik, Jean Jacques Drouin, Andres Garcia, Yang Tse, Gisle Vanem, Dan
Fandrich, Alexander Lazic, Michael Jahn, Andrew Benham, Bryan Henderson,
David Shaw, Jon Turner, Duane Cathey, Michal Marek, Philippe Vaucher, Kent
- Boortz, Karl M
+ Boortz, Karl Moerder, Shmulik Regev
Thanks! (and sorry if I forgot to mention someone)
diff --git a/TODO-RELEASE b/TODO-RELEASE
index 8c3413864..0356d96a5 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -3,6 +3,4 @@ To get fixed in 7.15.2 (planned release: Febrary 2006)
63 - bug #1431750
-64 - DNS caching set to 0, prune sooner
-
65 -
diff --git a/lib/hostip.c b/lib/hostip.c
index 91f59af2a..6cf652f87 100644
--- a/lib/hostip.c
+++ b/lib/hostip.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -276,6 +276,39 @@ void Curl_hostcache_prune(struct SessionHandle *data)
Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
}
+static int
+remove_entry_if_stale(struct SessionHandle *data, struct Curl_dns_entry *dns)
+{
+ struct hostcache_prune_data user;
+
+ if( !dns || (data->set.dns_cache_timeout == -1) || !data->hostcache)
+ /* cache forever means never prune, and NULL hostcache means
+ we can't do it */
+ return 0;
+
+ time(&user.now);
+ user.cache_timeout = data->set.dns_cache_timeout;
+
+ if ( !hostcache_timestamp_remove(&user,dns) )
+ return 0;
+
+ /* ok, we do need to clear the cache. although we need to remove just a
+ single entry we clean the entire hash, as no explicit delete function
+ is provided */
+ if(data->share)
+ Curl_share_lock(data, CURL_LOCK_DATA_DNS, CURL_LOCK_ACCESS_SINGLE);
+
+ Curl_hash_clean_with_criterium(data->hostcache,
+ (void *) &user,
+ hostcache_timestamp_remove);
+
+ if(data->share)
+ Curl_share_unlock(data, CURL_LOCK_DATA_DNS);
+
+ return 1;
+}
+
+
#ifdef HAVE_SIGSETJMP
/* Beware this is a global and unique instance. This is used to store the
return address that we can jump back to from inside a signal handler. This
@@ -405,6 +438,11 @@ int Curl_resolv(struct connectdata *conn,
/* free the allocated entry_id again */
free(entry_id);
+ /* See whether the returned entry is stale. Deliberately done after the
+ locked block */
+ if ( remove_entry_if_stale(data,dns) )
+ dns = NULL; /* the memory deallocation is being handled by the hash */
+
rc = CURLRESOLV_ERROR; /* default to failure */
if (!dns) {