Skip to content

IoUring: preserve readPending when rescheduling cancelled reads (#17087) - #17090

Merged
normanmaurer merged 1 commit into
5.0from
pending5
Jul 11, 2026
Merged

normanmaurer merged 1 commit into
5.0from
pending5

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Motivation:

Fix a read stall reported in #17049. With autoRead disabled, an explicit
read can be lost when a cancelled RECV completion races with an active
multishot POLL_ADD.

T0  A multishot POLL_ADD(POLLIN) is active.

T1  Netty submits a normal RECV.

T2  clearRead() cancels the RECV.
    -> readPending = false

T3  user calls channel.read() before the cancel CQE arrives.
    -> readPending = true
    -> doBeginReadNow() skips submitting RECV because POLL_ADD is still active

T4  the cancelled RECV completes with -ECANCELED.
    -> pending is captured as true
    -> completion handling clears readPending = false

T5  current behavior:
    -> doBeginReadNow() is called, but readPending is already false
    -> later POLLIN only sets socketHasMoreData
    -> no RECV is submitted, so the response stalls

One-shot POLL_ADD usually avoids this because its POLLIN completion
clears the poll state first. Multishot POLL_ADD remains scheduled, so
the later cancelled RECV completion can clear the only readPending
signal.

This race depends on CQE ordering, so it is hard to cover with a stable
unit test.

Modification:

Restore readPending before rescheduling a read when a cancelled read
completion observed a pending read. This also covers the equivalent
one-shot POLLIN interleaving.

Result:

Fixes #17049.

Motivation:

Fix a read stall reported in #17049. With autoRead disabled, an explicit
read can be lost when a cancelled RECV completion races with an active
multishot POLL_ADD.

```text
T0  A multishot POLL_ADD(POLLIN) is active.

T1  Netty submits a normal RECV.

T2  clearRead() cancels the RECV.
    -> readPending = false

T3  user calls channel.read() before the cancel CQE arrives.
    -> readPending = true
    -> doBeginReadNow() skips submitting RECV because POLL_ADD is still active

T4  the cancelled RECV completes with -ECANCELED.
    -> pending is captured as true
    -> completion handling clears readPending = false

T5  current behavior:
    -> doBeginReadNow() is called, but readPending is already false
    -> later POLLIN only sets socketHasMoreData
    -> no RECV is submitted, so the response stalls
```

One-shot POLL_ADD usually avoids this because its POLLIN completion
clears the poll state first. Multishot POLL_ADD remains scheduled, so
the later cancelled RECV completion can clear the only readPending
signal.

This race depends on CQE ordering, so it is hard to cover with a stable
unit test.

Modification:

Restore readPending before rescheduling a read when a cancelled read
completion observed a pending read. This also covers the equivalent
one-shot POLLIN interleaving.

Result:

Fixes #17049.
@normanmaurer
normanmaurer merged commit 77aba1a into 5.0 Jul 11, 2026
12 of 13 checks passed
@normanmaurer
normanmaurer deleted the pending5 branch July 11, 2026 06:57
@normanmaurer normanmaurer added this to the 5.0.0.Final milestone Jul 11, 2026
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