WordPress / WordPress/Requests

Check if system has support for sub-second connect timeouts (CURL_VERSION_ASYNCHDNS)

Open
#264 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
3.6k
Forks
500
Avg merge
2d 21h
Merged PRs (30d)
5

Description

Related to 4e1c18ff40568addd2f50b23e86e382766e7f3ba. I ask for this because I want to have a 'timeout' of less than a second.

It seems like it should be possible to avoid using signals such as alarm() (via CURLOPT_NOSIGNAL), and to detect if there is an alternative dns resolver (via CURL_VERSION_ASYNCHDNS)

https://curl.haxx.se/libcurl/c/curl_version_info.html

features can have none, one or more bits set, and the currently defined bits are:
...
CURL_VERSION_ASYNCHDNS

libcurl was built with support for asynchronous name lookups, which allows more exact timeouts (even > on Windows) and less blocking when using the multi interface. (added in 7.10.7)

http://stackoverflow.com/questions/25998063/how-can-i-tell-if-the-libcurl-installed-has-asynchronous-dns-enabled also mentions this.

Also, a workaround (when ASYNCDNS is absent) might be to disable timeouts for dns lookup (if the 'connect' time is sub-millisecond), so that the request timeout can be set to less than one second. I'm not sure if that will introduce new bugs, e.g. if DNS is slow/unreliable.

http://www.dsm.fordham.edu/cgi-bin/man-cgi.pl?topic=CURLOPT_NOSIGNAL&ampsect=3

  If this option is set and libcurl has been built with the standard name
  resolver,  timeouts  will not occur while the name resolve takes place.
  Consider building libcurl with the c-ares or threaded resolver backends
  to  enable  asynchronous  DNS  lookups,  to  enable  timeouts  for name
  resolves without the use of signals.

On an unrelated note, is the minimum necessary if the host name is an IPV4 or IPV6 address (e.g. 127.0.0.1, etc.), and HTTP redirects are disabled? (may have to set CURLOPT_NOSIGNAL so that the "lookup" will still avoid timing out)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with related commit 4e1c18ff40568addd2f50b23e86e382766e7f3ba and the existing timeout handling. Read libcurl's curl_version_info documentation for CURL_VERSION_ASYNCHDNS and CURLOPT_NOSIGNAL, then determine the supported behavior for sub-second connect timeouts and the IPv4/IPv6 case. Done means the implementation scope and compatibility constraints are established.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, networking
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
22/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.