Skip to content

Commit d19257f

Browse files
Copilotithewei
andcommitted
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>
1 parent 899eb0d commit d19257f

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

base/hsocket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ int ConnectTimeout(const char* host, int port, int ms) {
346346
unsigned int elapsed = gettick_ms() - start_time;
347347
int remaining = ms - (int)elapsed;
348348
if (remaining <= 0) {
349-
errno = ETIMEDOUT;
350-
return socket_errno_negative(connfd);
349+
closesocket(connfd);
350+
return -ETIMEDOUT;
351351
}
352352
return ConnectFDTimeout(connfd, remaining);
353353
}

0 commit comments

Comments
 (0)