Skip to content

Conversation

@tkarthikan
Copy link

Fixes #751

Problem
On UNIX systems, ConnectFDTimeout() uses select() to wait for a non-blocking connect to complete. However, select() has a hard limit of FD_SETSIZE (typically 1024) for file descriptors. When an application has many open connections and the socket fd is >= 1024, using FD_SET() causes undefined behavior, typically resulting in memory corruption or a crash.

Solution
Replace select() with poll() on UNIX platforms. poll() has no such fd limit since it uses an array of pollfd structures rather than a fixed-size bitmask.

Windows continues to use select() because its fd_set implementation is not bitmask-based and does not have this limitation.

@tkarthikan tkarthikan changed the title Fix: Use poll() for connect timeout on UNIX to avoid FD_SETSIZE limit fix: Use poll() for connect timeout on UNIX to avoid FD_SETSIZE limit Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConnectFDTimeout crashed with fd size

1 participant