Skip to content

wasip3: Implement read/write timeouts#762

Open
alexcrichton wants to merge 2 commits intoWebAssembly:mainfrom
alexcrichton:implement-timeouts
Open

wasip3: Implement read/write timeouts#762
alexcrichton wants to merge 2 commits intoWebAssembly:mainfrom
alexcrichton:implement-timeouts

Conversation

@alexcrichton
Copy link
Collaborator

This is needed for socket options with TCP/UDP to implement timed-out reads/writes. This plumbs the relevant timeout to the waitable-set.wait invocation and handles the timeout outwards from there. This is a bit tricky since timeouts/cancellation can all race with actual completion of the operation, which is handled throughout and along the way, too.

@alexcrichton alexcrichton requested a review from dicej March 5, 2026 00:00
@alexcrichton alexcrichton force-pushed the implement-timeouts branch 2 times, most recently from 2cae64f to bdef648 Compare March 5, 2026 21:38
alexcrichton added a commit to alexcrichton/wasi-libc that referenced this pull request Mar 6, 2026
In WebAssembly#762 I'm seeing an error related to `EADDRINUSE` which I can't
reproduce locally. Tests currently all use the same port which means
that they are required to be run serially and additionally may run into
this risk if the port happens to already be taken. I don't really know
what's going on in CI, but I wanted to nevertheless refactor these tests.

This commit rearchitects, rewrites, and fixes sockets-related tests.
Changes here are:

* Servers now print the port they're listening to. Clients read this
  port and then connect to that port. This orchestration happens through
  some specially crafted bash and CMake, similar to before. All tests
  now bind to port 0 to get an OS-assigned port instead of picking a port.

* All tests are now ungated, notably enabling some nonblocking I/O tests
  that were previously gated.

* A number of tests are refactored or updated to be less flaky. Many
  tests were failing nondeterministically locally due to how the test
  was constructed and assuming certain things were ready when they may
  not be. Some tests were entirely rewritten, such as
  `sockets-nonblocking-multiple.c`, while others were only lightly
  refactored to `poll` in a few more places.

* All tests are updated to pass in less than 100ms. Some tests before
  hung for awhile as timeouts were reached for example, but this wasn't
  a necessary part of the test. Other tests for nonblocking I/O had many
  calls to `poll` with a number of them reaching the timeout. These are
  rewritten to use a single call to `poll` with no timeout which enables
  the test to progress much faster as timeouts are never reached.

Overall the intent is that the sockets-related tests are more
comprehensive now, more robust and/or less flaky, and work in more
environments.
alexcrichton added a commit to alexcrichton/wasi-libc that referenced this pull request Mar 6, 2026
In WebAssembly#762 I'm seeing an error related to `EADDRINUSE` which I can't
reproduce locally. Tests currently all use the same port which means
that they are required to be run serially and additionally may run into
this risk if the port happens to already be taken. I don't really know
what's going on in CI, but I wanted to nevertheless refactor these tests.

This commit rearchitects, rewrites, and fixes sockets-related tests.
Changes here are:

* Servers now print the port they're listening to. Clients read this
  port and then connect to that port. This orchestration happens through
  some specially crafted bash and CMake, similar to before. All tests
  now bind to port 0 to get an OS-assigned port instead of picking a port.

* All tests are now ungated, notably enabling some nonblocking I/O tests
  that were previously gated.

* A number of tests are refactored or updated to be less flaky. Many
  tests were failing nondeterministically locally due to how the test
  was constructed and assuming certain things were ready when they may
  not be. Some tests were entirely rewritten, such as
  `sockets-nonblocking-multiple.c`, while others were only lightly
  refactored to `poll` in a few more places.

* All tests are updated to pass in less than 100ms. Some tests before
  hung for awhile as timeouts were reached for example, but this wasn't
  a necessary part of the test. Other tests for nonblocking I/O had many
  calls to `poll` with a number of them reaching the timeout. These are
  rewritten to use a single call to `poll` with no timeout which enables
  the test to progress much faster as timeouts are never reached.

Overall the intent is that the sockets-related tests are more
comprehensive now, more robust and/or less flaky, and work in more
environments.
alexcrichton added a commit to alexcrichton/wasi-libc that referenced this pull request Mar 6, 2026
In WebAssembly#762 I'm seeing an error related to `EADDRINUSE` which I can't
reproduce locally. Tests currently all use the same port which means
that they are required to be run serially and additionally may run into
this risk if the port happens to already be taken. I don't really know
what's going on in CI, but I wanted to nevertheless refactor these tests.

This commit rearchitects, rewrites, and fixes sockets-related tests.
Changes here are:

* Servers now print the port they're listening to. Clients read this
  port and then connect to that port. This orchestration happens through
  some specially crafted bash and CMake, similar to before. All tests
  now bind to port 0 to get an OS-assigned port instead of picking a port.

* All tests are now ungated, notably enabling some nonblocking I/O tests
  that were previously gated.

* A number of tests are refactored or updated to be less flaky. Many
  tests were failing nondeterministically locally due to how the test
  was constructed and assuming certain things were ready when they may
  not be. Some tests were entirely rewritten, such as
  `sockets-nonblocking-multiple.c`, while others were only lightly
  refactored to `poll` in a few more places.

* All tests are updated to pass in less than 100ms. Some tests before
  hung for awhile as timeouts were reached for example, but this wasn't
  a necessary part of the test. Other tests for nonblocking I/O had many
  calls to `poll` with a number of them reaching the timeout. These are
  rewritten to use a single call to `poll` with no timeout which enables
  the test to progress much faster as timeouts are never reached.

Overall the intent is that the sockets-related tests are more
comprehensive now, more robust and/or less flaky, and work in more
environments.
In WebAssembly#762 I'm seeing an error related to `EADDRINUSE` which I can't
reproduce locally. Tests currently all use the same port which means
that they are required to be run serially and additionally may run into
this risk if the port happens to already be taken. I don't really know
what's going on in CI, but I wanted to nevertheless refactor these tests.

This commit rearchitects, rewrites, and fixes sockets-related tests.
Changes here are:

* Servers now print the port they're listening to. Clients read this
  port and then connect to that port. This orchestration happens through
  some specially crafted bash and CMake, similar to before. All tests
  now bind to port 0 to get an OS-assigned port instead of picking a port.

* All tests are now ungated, notably enabling some nonblocking I/O tests
  that were previously gated.

* A number of tests are refactored or updated to be less flaky. Many
  tests were failing nondeterministically locally due to how the test
  was constructed and assuming certain things were ready when they may
  not be. Some tests were entirely rewritten, such as
  `sockets-nonblocking-multiple.c`, while others were only lightly
  refactored to `poll` in a few more places.

* All tests are updated to pass in less than 100ms. Some tests before
  hung for awhile as timeouts were reached for example, but this wasn't
  a necessary part of the test. Other tests for nonblocking I/O had many
  calls to `poll` with a number of them reaching the timeout. These are
  rewritten to use a single call to `poll` with no timeout which enables
  the test to progress much faster as timeouts are never reached.

Overall the intent is that the sockets-related tests are more
comprehensive now, more robust and/or less flaky, and work in more
environments.
This is needed for socket options with TCP/UDP to implement timed-out
reads/writes. This plumbs the relevant timeout to the waitable-set.wait
invocation and handles the timeout outwards from there. This is a bit
tricky since timeouts/cancellation can all race with actual completion
of the operation, which is handled throughout and along the way, too.
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.

2 participants