You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix connect timeout not accounting for DNS resolution time (#810)
* Initial plan
* Fix connect timeout not accounting for DNS resolution time
The ConnectTimeout function previously only applied the timeout to the
TCP connect phase (poll/select), but DNS resolution via getaddrinfo()
had no timeout applied. On platforms like Android with no network,
getaddrinfo() can block for 30-40 seconds, making user-set
connect_timeout and timeout values ineffective.
Changes:
- ConnectTimeout now tracks elapsed time for DNS resolution and
subtracts it from the TCP connect timeout. If DNS takes longer
than the timeout, it returns ETIMEDOUT immediately.
- http_client_connect adjusts SSL handshake timeout by subtracting
time already spent on DNS+TCP connect.
- http_client_exec checks overall request timeout after connect,
handling cases where connect took longer than expected.
- Updated build files (CMakeLists.txt, Makefile) to link htime.c
with all targets that use hsocket.c.
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
* Address code review: use consistent error handling and fail immediately on SSL timeout
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
* Use CHECK_TIMEOUT after connect and add hsocket.c+htime.c to nslookup target
- Replace inline timeout check with CHECK_TIMEOUT macro by moving
variable declarations before the connect: label to avoid crossing
initializations with goto.
- Add hsocket.c and htime.c to nslookup CMake target for Windows
link compatibility (dns.c calls WSAInit from hsocket.c).
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
* Add explicit closesocket(connfd) in ConnectTimeout before returning -ETIMEDOUT
When DNS resolution exhausts the timeout budget, explicitly close the
socket with closesocket() and return -ETIMEDOUT directly, instead of
relying on socket_errno_negative() which reads errno indirectly and
could return the wrong error code on Windows.
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
0 commit comments