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

JNI/JSSE: Add support for poll(), fix for EAGAIN and select() #201

Merged
merged 2 commits into from
Jul 11, 2024

Conversation

cconlon
Copy link
Member

@cconlon cconlon commented Jun 11, 2024

Addition of poll() Support:

This PR adds support for using poll() by default instead of select() on native file descriptors. The previous select() behavior was left in tact and used as a default for Windows builds still. select() can also be used by building the native JNI library with WOLFJNI_USE_IO_SELECT defined. See java.sh cflags section for where that could be added.

We do not monitor lots of file descriptors at once ourselves inside wolfSSL JNI/JSSE, but one disadvantage to using select() is that for file descriptor numbers larger than FD_SETSIZE, the FD_ISSET and related macros result in undefined behavior. FD_SETSIZE defaults to 1024 on most systems, so is not very scalable for consumers using wolfSSL JNI/JSSE in processes that are opening and using lots of file descriptors.


Changes to select() Support:

Native JNI socketSelect() loops around calling select() if it returns -1 and errno == EINTR. According to the select(2) man page, some variants of Unix may return EAGAIN from select(). This PR adjusts our socketSelect() to also loop on EAGAIN.

VERSIONS
       On some other UNIX systems, select() can fail with the error
       EAGAIN if the system fails to allocate kernel-internal resources,
       rather than ENOMEM as Linux does.  POSIX specifies this error for
       poll(2), but not for select().  Portable programs may wish to
       check for EAGAIN and loop, just as with EINTR.

Man page for select() from OSX also shows a potential return of EAGAIN from select():

ERRORS
     An error return from select() indicates:

     [EAGAIN]           The kernel was (perhaps temporarily) unable to allocate the requested number of file descriptors.

Related to ZD 17962 (and 17385) - customer confirmed fix seems to be working well so far.

@cconlon cconlon self-assigned this Jun 11, 2024
@cconlon cconlon changed the title JNI: call select() again when return -1 and errno is EAGAIN JNI/JSSE: Add support for poll(), fix for EAGAIN and select() Jun 26, 2024
@JacobBarthelmeh JacobBarthelmeh merged commit bef6379 into wolfSSL:master Jul 11, 2024
35 checks passed
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.

3 participants