-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resolve
option (DNS cache) not honored with persistent handles
#45
Comments
Thanks four your report! We cannot add the IP to the persistent handle ID, because we do not know it beforehand. We'd rather have to look how to handle issues with the DNS cache. I'll first try to determine the intended behavior of related options within libcurl. |
Is the If so, we could seed the handle with the |
At a first glance, everything is working as expected: https://curl.haxx.se/libcurl/c/CURLOPT_RESOLVE.html Implementing |
Let me try to explain the issue in a different way: I am using the What I observe seems to be the following: If later another HTTP request to X is issued, and at the same time the persistent TCP connection is about to be closed ( However, a fresh connection will be opened - this time without taking the Unfortunately, in this way, the |
I'm still not sure I understand correctly.
This sounds like we should check for a bug in libcurl. Do you set |
Yes, we do! However, it is complicated to reproduce :) I use this script in PHP-FPM:
restart php-fpm to clear any connections and then call the script a couple of times. all requests go to localhost:80 where we have an apache running. From the Then comes the boring part:
When I now hit reload in the browser, my request goes to the real example.com and not to localhost.
Maybe :) We use the CentOS 7 system package |
Oh, somehow I thought you were using libcurl >= 7.41 -- no idea where I got his from :-/ Does the CentOS 7 system package use an asynchronous resolver (c-ares or threaded; check with Would you mind to check whether your issue disappears with a libcurl >= 7.38? Thank you! |
I'm still unable to reproduce this with libcurl built from tag Restarting the target webserver, shuts down the socket on the server side and puts it in CLOSE_WAIT state. For me, libcurl detects the dead connection and correctly creates a new one with the information found in the DNS cache. |
yes, it does.
I can reproduce the error with 7.29.0 (the base for the centos 7.2 libcurl) with this configuration
and I cannot reproduce it with curl >= 7.35. |
At first, I have experimented with restarting the webserver, too. But that doesn't seem to fail reliably. After establishing the connection to localhost I have to wait for about a minute before the "server" part of the connection disappears from netstat. Then, the re-connect goes to example.com (reliably). I have not yet figured out which timeout is responsible. Lowering |
Okay, I've been able to reproduce it with 7.29 and setting So, it looks like an old libcurl bug to me where those entries were expiring, while they shouldn't. I couldn't find an explicit change log entry about such an issue, but, ugh, there've been more than 20 releases since. |
you're debugging 60 times faster than me :)
does that mean, that any resolve-option will be useless after the first dns_cache_timeout has passed, until the fpm-child restarts?
hm. do you know any workaround that would avoid this issue with 7.29/centos7? |
That's a hard one. Maybe a A better solution might be to run and control your own DNS forwarder/cache to be used by libcurl https://mdref.m6w6.name/http/Client/Curl#$dns_servers. |
Gosh, that's only available with the c-ares resolver (unless you want the whole host to use the custom DNS cache/forwarder). |
resolve
option (DNS cache) not honored with persistent handles
We'll try that one.
Might be because of @rcanavans comment in #37. We support multiple distributions and therefore link against different versions of |
Does the |
Quite a good question, actually. My wild guess is "no, you can't". All requests (curl easy handles) share the DNS cache of the client (curl multi handle), so I think each request with different options affects the shared DNS cache. |
As you suggested, our workaround is now setting the TTL to a day on requests that use pre-resolved DNS. Thus, the entries stay long enough in curl's DNS cache to be still available when a stale persistent connection is reconnected. (Problem solved). In our setup a domain is either always or never pre-resolved. So we shouldn't have problems with conflicting DNS entries. As our FPM processes have a life span that is usually much short than a day, I don't expect side effects of the long TTL. (Hopefully: No new problem opened). I'd say, let's close this as "documented" :) Thanks a lot for your help! |
Alright, re-open at will! Thanks. |
+ Added http\Client\Curl\User interface for userland event loops + Added http\Url::IGNORE_ERRORS, http\Url::SILENT_ERRORS and http\Url::STDFLAGS + Added http\Client::setDebug(callable $debug) + Added http\Client\Curl\FEATURES constants and namespace + Added http\Client\Curl\VERSIONS constants and namespace + Added share_cookies and share_ssl (libcurl >= 7.23.0) options to http\Client::configure() + http\Client uses curl_share handles to properly share cookies and SSL/TLS sessions between requests + Improved configure checks for default CA bundles + Improved negotiation precision * Fixed regression introduced by http\Params::PARSE_RFC5987: negotiation using the params parser would receive param keys without the trailing asterisk, stripped by http\Params::PARSE_RFC5987. * Fix gh-issue #50: http\Client::dequeue() within http\Client::setDebug() causes segfault (Mike, Maik Wagner) * Fix gh-issue #47: http\Url: Null pointer deref in sanitize_value() (Mike, @rc0r) * Fix gh-issue #45: HTTP/2 response message parsing broken with libcurl >= 7.49.1 (Mike) * Fix gh-issue #43: Joining query with empty original variable in query (Mike, Sander Backus) * Fix gh-issue #42: fatal error when using punycode in URLs (Mike, Sebastian Thielen) * Fix gh-issue #41: Use curl_version_info_data.features when initializing options (Mike) * Fix gh-issue #40: determinde the SSL backend used by curl at runtime (Mike, @rcanavan) * Fix gh-issue #39: Notice: http\Client::enqueue(): Could not set option proxy_service_name (Mike, @rcanavan) * Fix gh-issue #38: Persistent curl handles: error code not properly reset (Mike, @afflerbach) * Fix gh-issue #36: Unexpected cookies sent if persistent_handle_id is used (Mike, @rcanavan, @afflerbach) * Fix gh-issue #34: allow setting multiple headers with the same name (Mike, @rcanavan) * Fix gh-issue #33: allow setting prodyhost request option to NULL (Mike, @rcanavan) * Fix gh-issue #31: add/improve configure checks for default CA bundle/path (Mike, @rcanavan) Changes from beta1: * Fixed PHP-5.3 compatibility * Fixed recursive calls to the event loop dispatcher Changes from beta2: * Fix bug #73055: crash in http\QueryString (Mike, @rc0r) (CVE-2016-7398) * Fix bug #73185: Buffer overflow in HTTP parse_hostinfo() (Mike, @rc0r) * Fix HTTP/2 version parser for older libcurl versions (Mike)
+ Added http\Client\Curl\User interface for userland event loops + Added http\Url::IGNORE_ERRORS, http\Url::SILENT_ERRORS and http\Url::STDFLAGS + Added http\Client::setDebug(callable $debug) + Added http\Client\Curl\FEATURES constants and namespace + Added http\Client\Curl\VERSIONS constants and namespace + Added share_cookies and share_ssl (libcurl >= 7.23.0) options to http\Client::configure() + http\Client uses curl_share handles to properly share cookies and SSL/TLS sessions between requests + Improved configure checks for default CA bundles + Improved negotiation precision * Fixed regression introduced by http\Params::PARSE_RFC5987: negotiation using the params parser would receive param keys without the trailing asterisk, stripped by http\Params::PARSE_RFC5987. * Fix gh-issue #50: http\Client::dequeue() within http\Client::setDebug() causes segfault (Mike, Maik Wagner) * Fix gh-issue #47: http\Url: Null pointer deref in sanitize_value() (Mike, @rc0r) * Fix gh-issue #45: HTTP/2 response message parsing broken with libcurl >= 7.49.1 (Mike) * Fix gh-issue #43: Joining query with empty original variable in query (Mike, Sander Backus) * Fix gh-issue #42: fatal error when using punycode in URLs (Mike, Sebastian Thielen) * Fix gh-issue #41: Use curl_version_info_data.features when initializing options (Mike) * Fix gh-issue #40: determinde the SSL backend used by curl at runtime (Mike, @rcanavan) * Fix gh-issue #39: Notice: http\Client::enqueue(): Could not set option proxy_service_name (Mike, @rcanavan) * Fix gh-issue #38: Persistent curl handles: error code not properly reset (Mike, @afflerbach) * Fix gh-issue #36: Unexpected cookies sent if persistent_handle_id is used (Mike, @rcanavan, @afflerbach) * Fix gh-issue #34: allow setting multiple headers with the same name (Mike, @rcanavan) * Fix gh-issue #33: allow setting prodyhost request option to NULL (Mike, @rcanavan) * Fix gh-issue #31: add/improve configure checks for default CA bundle/path (Mike, @rcanavan) Changes from beta1: * Fixed recursive calls to the event loop dispatcher Changes from beta2: + Improved configure checks for IDNA libraries (added --with-http-libicu-dir, --with-http-libidnkit{,2}-dir, --with-http-libidn2-dir) * Fix bug #73055: crash in http\QueryString (Mike, @rc0r) (CVE-2016-7398) * Fix bug #73185: Buffer overflow in HTTP parse_hostinfo() (Mike, @rc0r) * Fix HTTP/2 version parser for older libcurl versions (Mike) * Fix gh-issue #52: Underscores in host names: libidn Failed to parse IDN (Mike, @canavan)
+ Added http\Client\Curl\User interface for userland event loops + Added http\Url::IGNORE_ERRORS, http\Url::SILENT_ERRORS and http\Url::STDFLAGS + Added http\Client::setDebug(callable $debug) + Added http\Client\Curl\FEATURES constants and namespace + Added http\Client\Curl\VERSIONS constants and namespace + Added share_cookies and share_ssl (libcurl >= 7.23.0) options to http\Client::configure() + http\Client uses curl_share handles to properly share cookies and SSL/TLS sessions between requests + Improved configure checks for default CA bundles + Improved negotiation precision * Fixed regression introduced by http\Params::PARSE_RFC5987: negotiation using the params parser would receive param keys without the trailing asterisk, stripped by http\Params::PARSE_RFC5987. * Fix gh-issue #50: http\Client::dequeue() within http\Client::setDebug() causes segfault (Mike, Maik Wagner) * Fix gh-issue #47: http\Url: Null pointer deref in sanitize_value() (Mike, @rc0r) * Fix gh-issue #45: HTTP/2 response message parsing broken with libcurl >= 7.49.1 (Mike) * Fix gh-issue #43: Joining query with empty original variable in query (Mike, Sander Backus) * Fix gh-issue #42: fatal error when using punycode in URLs (Mike, Sebastian Thielen) * Fix gh-issue #41: Use curl_version_info_data.features when initializing options (Mike) * Fix gh-issue #40: determinde the SSL backend used by curl at runtime (Mike, @rcanavan) * Fix gh-issue #39: Notice: http\Client::enqueue(): Could not set option proxy_service_name (Mike, @rcanavan) * Fix gh-issue #38: Persistent curl handles: error code not properly reset (Mike, @afflerbach) * Fix gh-issue #36: Unexpected cookies sent if persistent_handle_id is used (Mike, @rcanavan, @afflerbach) * Fix gh-issue #34: allow setting multiple headers with the same name (Mike, @rcanavan) * Fix gh-issue #33: allow setting prodyhost request option to NULL (Mike, @rcanavan) * Fix gh-issue #31: add/improve configure checks for default CA bundle/path (Mike, @rcanavan) Changes from beta1: * Fixed PHP-5.3 compatibility * Fixed recursive calls to the event loop dispatcher Changes from beta2: * Fix bug #73055: crash in http\QueryString (Mike, @rc0r) (CVE-2016-7398) * Fix bug #73185: Buffer overflow in HTTP parse_hostinfo() (Mike, @rc0r) (CVE-2016-7961) * Fix HTTP/2 version parser for older libcurl versions (Mike)
+ Added http\Client\Curl\User interface for userland event loops + Added http\Url::IGNORE_ERRORS, http\Url::SILENT_ERRORS and http\Url::STDFLAGS + Added http\Client::setDebug(callable $debug) + Added http\Client\Curl\FEATURES constants and namespace + Added http\Client\Curl\VERSIONS constants and namespace + Added share_cookies and share_ssl (libcurl >= 7.23.0) options to http\Client::configure() + http\Client uses curl_share handles to properly share cookies and SSL/TLS sessions between requests + Improved configure checks for default CA bundles + Improved negotiation precision * Fixed regression introduced by http\Params::PARSE_RFC5987: negotiation using the params parser would receive param keys without the trailing asterisk, stripped by http\Params::PARSE_RFC5987. * Fix gh-issue #50: http\Client::dequeue() within http\Client::setDebug() causes segfault (Mike, Maik Wagner) * Fix gh-issue #47: http\Url: Null pointer deref in sanitize_value() (Mike, @rc0r) * Fix gh-issue #45: HTTP/2 response message parsing broken with libcurl >= 7.49.1 (Mike) * Fix gh-issue #43: Joining query with empty original variable in query (Mike, Sander Backus) * Fix gh-issue #42: fatal error when using punycode in URLs (Mike, Sebastian Thielen) * Fix gh-issue #41: Use curl_version_info_data.features when initializing options (Mike) * Fix gh-issue #40: determinde the SSL backend used by curl at runtime (Mike, @rcanavan) * Fix gh-issue #39: Notice: http\Client::enqueue(): Could not set option proxy_service_name (Mike, @rcanavan) * Fix gh-issue #38: Persistent curl handles: error code not properly reset (Mike, @afflerbach) * Fix gh-issue #36: Unexpected cookies sent if persistent_handle_id is used (Mike, @rcanavan, @afflerbach) * Fix gh-issue #34: allow setting multiple headers with the same name (Mike, @rcanavan) * Fix gh-issue #33: allow setting prodyhost request option to NULL (Mike, @rcanavan) * Fix gh-issue #31: add/improve configure checks for default CA bundle/path (Mike, @rcanavan) Changes from beta1: * Fixed recursive calls to the event loop dispatcher Changes from beta2: + Improved configure checks for IDNA libraries (added --with-http-libicu-dir, --with-http-libidnkit{,2}-dir, --with-http-libidn2-dir) * Fix bug #73055: crash in http\QueryString (Mike, @rc0r) (CVE-2016-7398) * Fix bug #73185: Buffer overflow in HTTP parse_hostinfo() (Mike, @rc0r) (CVE-2016-7961) * Fix HTTP/2 version parser for older libcurl versions (Mike) * Fix gh-issue #52: Underscores in host names: libidn Failed to parse IDN (Mike, @canavan)
A client with persistent handle sends requests to unexpected hosts when using the pre-populated DNS cache via the
resolve
option:I expected it to open a fresh connection when the
resolve
option is actually effective.The text was updated successfully, but these errors were encountered: