Problem
Requests to the Telegram messaging API on a docker container at work took 5 seconds:
$ time curl --silent api.telegram.org --output /dev/null real 0m5.577s
Doing a IPv4-only request was quick:
$ time curl -4 --silent api.telegram.org --output /dev/null real 0m0.090s
Cause
Inspecting the network traffic with wireshark shows that two DNS are made: One for the IPv4 address, one for the IPv6 address.
The IPv4 address is immediately resolved, but the IPv6 request is cancelled after 5 seconds:
Solution
A thread on askubuntu.com gave me the hint what to do: Disable parallel DNS requests, so that the IPv4 request is sent first. Only if that fails, the IPv6 request will be made.
/etc/resolv.conf
options single-request