dicej requested wasmtime-wasi-reviewers for a review on PR #12629.
dicej opened PR #12629 from dicej:outgoing-datagram-stream-pollable-fix to bytecodealliance:main:
Previously,
OutgoingDatagramStreamused itssend_statefield to determine whether the socket was ready for writing without necessarily polling thetokio::net::UdpSocket. The underlying assumption was that a freshly-bound socket would be immediately ready for writing, but that's not true fortokio.tokioassumes a socket is not ready for _anything_ by default and relies on e.g.epollto tell it otherwise.In practice, this meant the
Pollable::readyimpl forOutgoingDatagramStreamwould resolve immediately for a fresh socket, leaving the guest to race withtokio's use ofepoll. Usually,tokiowon and all was well, but occasionally it lost and theOutgoingDatagramStream::sendcall would returnOk(0)(meaning "would block") leaving the guest confused since it was just told that the socket was ready for writing.This commit removes
SendStateentirely, relying exclusively ontokio::net::UdpSocket::readyfor thePollableandcheck_sendimplementations. As a side effect, we no longer attempt to prevent the guest from sending more datagrams thancheck_sendindicated since the number returned bycheck_sendis only a guess anyway, andtokiowill push back if it needs to. Forp3, the wholecheck_send/sendpattern is gone, so we won't need to concern ourselves with it going forward.Fixes #12612
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
dicej requested cfallin for a review on PR #12629.
dicej requested wasmtime-core-reviewers for a review on PR #12629.
dicej requested alexcrichton for a review on PR #12629.
dicej unassigned cfallin from PR #12629 fix Pollable impl for OutgoingDatagramStream.
cc @badeend in case you're interested
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Could this additionally
debug_assert!thatcount == 0?
alexcrichton commented on PR #12629:
Also, if you're up for it, I think it'd be good to test this on p3 too (semantically at least)
dicej updated PR #12629.
dicej has enabled auto merge for PR #12629.
dicej added PR #12629 fix Pollable impl for OutgoingDatagramStream to the merge queue
dicej merged PR #12629.
dicej removed PR #12629 fix Pollable impl for OutgoingDatagramStream from the merge queue
badeend commented on PR #12629:
As a side effect, we no longer attempt to prevent the guest from sending more datagrams than check_send indicated since the number returned by check_send is only a guess anyway
@dicej This violates the P2 spec:
Each call to
sendmust be permitted by a precedingcheck-send. Implementations must trap if eithercheck-sendwas not called ordatagramscontains more items thancheck-sendpermitted.Can the check be reintroduced?
@dicej This violates the P2 spec:
Each call to
sendmust be permitted by a precedingcheck-send. Implementations must trap if eithercheck-sendwas not called ordatagramscontains more items thancheck-sendpermitted.Can the check be reintroduced?
:face_palm: Yes, I'll do that on Monday. Thanks for catching that.
Last updated: Feb 24 2026 at 04:36 UTC