Skip to content

sockets: Add error code for EPIPE (and ECONNABORTED on Windows)#887

Merged
ricochet merged 1 commit intoWebAssembly:mainfrom
badeend:connection-broken
Mar 9, 2026
Merged

sockets: Add error code for EPIPE (and ECONNABORTED on Windows)#887
ricochet merged 1 commit intoWebAssembly:mainfrom
badeend:connection-broken

Conversation

@badeend
Copy link
Member

@badeend badeend commented Feb 25, 2026

WASI sockets currently has no error code corresponding to EPIPE. When writing to a closed/broken socket:

  • POSIX systems return EPIPE
  • Windows returns ECONNABORTED

After searching around, this Windows-specific discrepancy is well-known:


WASI doesn't have a good solution for it now:

  • By the time the OS reports EPIPE, previously acknowledged writes may have been lost and and the guest should be informed about that. So swallowing the error is not right.
  • Mapping it to ECONNRESET isn't right either, beause that implies that the peer actively reset the connection.
  • Mapping (or: leaving) it as ECONNABORTED isn't optimal either, because that error code is usually only returned by accept and sometimes connect on Unix-like systems.

I think this warrants a new error code. I've called it connection-broken. I expect wasi-libc to map this to EPIPE.


Wasmtime currently maps EPIPE to ok(()). With the new error code in place, this test can be updated to consistently expect an error cross platform.

@badeend badeend requested a review from a team as a code owner February 25, 2026 15:59
@github-actions github-actions bot added the P-sockets Proposal: wasi-sockets label Feb 25, 2026
Copy link
Contributor

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Rationale and everything makes sense to me FWIW, seems reasonable to me!

@badeend badeend force-pushed the connection-broken branch from f4e907d to 7c2b15d Compare March 5, 2026 21:10
@badeend
Copy link
Member Author

badeend commented Mar 9, 2026

@ricochet I'm not allowed to merge my own PRs. Would you mind merging this for me?

@ricochet
Copy link
Contributor

ricochet commented Mar 9, 2026

Ah we need approval from someone else in WASI Sockets Champions. Overriding now

@ricochet ricochet merged commit d2eef34 into WebAssembly:main Mar 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P-sockets Proposal: wasi-sockets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants