Skip to content

Replace select() with poll()#249

Merged
parfeon merged 2 commits into
masterfrom
CLEN-3441-fix-select-crash
May 14, 2026
Merged

Replace select() with poll()#249
parfeon merged 2 commits into
masterfrom
CLEN-3441-fix-select-crash

Conversation

@parfeon
Copy link
Copy Markdown
Contributor

@parfeon parfeon commented May 13, 2026

fix(socket): replace select() with poll() in pbpal_check_connect

Replace inline select()/FD_SET with poll() on non-Windows platforms in pbpal_check_connect(). On Linux and macOS FD_SET writes to a fixed 1024-bit bitmap and corrupts the stack when a socket fd value exceeds FD_SETSIZE. poll() has no fd-value limitation. Windows retains select() because its fd_set is array-based and safe.

test(poller): add unit tests for poll()-based callback poller

Add pbpal_ntf_callback_poller_poll_unit_test.c covering init/deinit, save/remove, watch events, poll detection of readable and writable sockets, multiple sockets, socket update, and a high fd number test case (fd=1500) that validates the fix for the FD_SETSIZE overflow.

Replace inline `select()`/`FD_SET` with `poll()` on non-Windows platforms in `pbpal_check_connect()`.
On Linux and macOS `FD_SET` writes to a fixed 1024-bit bitmap and corrupts the stack when a socket fd
value exceeds `FD_SETSIZE`. `poll()` has no fd-value limitation. Windows retains `select()` because its
`fd_set` is array-based and safe.

test(poller): add unit tests for `poll()`-based callback poller

Add `pbpal_ntf_callback_poller_poll_unit_test.c` covering init/deinit, save/remove, watch events,
poll detection of readable and writable sockets, multiple sockets, socket update, and a high fd
number test case (fd=1500) that validates the fix for the `FD_SETSIZE` overflow.
@parfeon parfeon self-assigned this May 13, 2026
@parfeon parfeon added status: done This issue is considered resolved. priority: high This PR should be reviewed ASAP. type: fix This PR contains fixes to existing features. labels May 13, 2026
Copy link
Copy Markdown
Contributor

@KGronek-Pubnub KGronek-Pubnub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@parfeon
Copy link
Copy Markdown
Contributor Author

parfeon commented May 14, 2026

@pubnub-release-bot release

@parfeon parfeon merged commit 61138ea into master May 14, 2026
7 checks passed
@parfeon parfeon deleted the CLEN-3441-fix-select-crash branch May 14, 2026 08:56
@pubnub-release-bot
Copy link
Copy Markdown
Contributor

🚀 Release successfully completed 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: high This PR should be reviewed ASAP. status: done This issue is considered resolved. type: fix This PR contains fixes to existing features.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants