WebAssembly / WebAssembly/component-model

Non-blocking I/O without cancellation

Open
#617 22 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
1.4k
Forks
130
Avg merge
2d 1h
Merged PRs (30d)
15

Description

Hi! The concurrency explainer contains an example on how to implement non-blocking IO.

  • write() calls stream.write, forwarding the caller's buffer.
  • If stream.write returns that it successfully copied some bytes without
    blocking, write() returns success.
  • Otherwise, to avoid blocking:
    • write() calls [stream.cancel-write] to regain ownership of the
      caller's buffer.
    • If select() has not indicated that this file descriptor is ready,
      write() starts a zero-length write and returns EWOULDBLOCK.
    • Otherwise, to avoid the potential infinite loop:
    • write() copies the contents of the caller's buffer into an
      internal buffer, starts a new stream.write to complete in the
      background using the internal buffer, and then returns success.
    • The above logic implicitly waits for this background stream.write
      to complete before the file descriptor is considered ready again.

But it also says:

Cancellation is cooperative, (...) allowing the subtask to continue executing for an arbitrary amount of time

Is there a contradiction here?

If the other end of a stream doesn't respect cancellation immediately (which is allowed) or doesn't support cancellation at all (also allowed) the guest will still end up being blocked.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read design/mvp/Concurrency.md sections "stream-readiness" and "cancellation" first, then compare the non-blocking I/O example with the stated cooperative-cancellation behavior. Determine whether the two descriptions are consistent and, if not, identify what clarification the explainer needs; completion requires a maintainer-approved resolution in the documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
operating-systems
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.