Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: lib: sockets: Unable to select() file descriptors with number >= 32 #34563

Closed
chyu313 opened this issue Apr 26, 2021 · 1 comment · Fixed by #34653
Closed

net: lib: sockets: Unable to select() file descriptors with number >= 32 #34563

chyu313 opened this issue Apr 26, 2021 · 1 comment · Fixed by #34653
Assignees
Labels
area: Networking area: POSIX POSIX API Library area: Sockets Networking sockets bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug

Comments

@chyu313
Copy link
Contributor

chyu313 commented Apr 26, 2021

Describe the bug
zsock_select() cannot poll file descriptors if all the file descriptors in readfds or writefds are all greater than or equal to 32.

To Reproduce

  1. Create 32 threads to accept 32 TCP connections, each thread handles one TCP connection. Some of the file descriptor returned by zsock_accept() are >= 32.
  2. In each thread, use zsock_select() to poll read event for the file descriptor. If the file descriptor >= 32, it never becomes ready for reading even there is data received.

Solution
In zsock_select(), when there is no any bit set in the first 32 bits of readfds, we should still add 32 to fd_no before iterating to next bitset, so I add fd_no += 32; as following (code in red color):

image

Environment (please complete the following information):

  • OS: Linux
  • Toolchain: Zephyr SDK
  • Commit: abb94b1
@chyu313 chyu313 added the bug The issue is a bug, or the PR is fixing a bug label Apr 26, 2021
@jukkar
Copy link
Member

jukkar commented Apr 26, 2021

@chyu313 could you send a PR for this?

@pfalcon pfalcon changed the title net: lib: sockets: Unable to poll file descriptor (number >= 32) net: lib: sockets: Unable to select() file descriptors with number >= 32 Apr 26, 2021
@pfalcon pfalcon added the area: Sockets Networking sockets label Apr 26, 2021
@jukkar jukkar added the priority: medium Medium impact/importance bug label Apr 27, 2021
jukkar pushed a commit that referenced this issue Apr 28, 2021
zsock_select() cannot poll file descriptors with number >= 32.

When a whole word in FD_SET was skipped due to being empty,
corresponding fd number was not updated, leading to wrong
fd's being passed to poll().

Fixes #34563

Signed-off-by: Chih Hung Yu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Networking area: POSIX POSIX API Library area: Sockets Networking sockets bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants