Skip to content

IdleStateHandler: reset firstWriter/ReaderIdleEvent in resetWriteTimeout/resetReadTimeout (#16982) - #16989

Merged
chrisvest merged 2 commits into
netty:4.1from
chrisvest:4.1-idle-state-handler
Jun 25, 2026
Merged

chrisvest merged 2 commits into
netty:4.1from
chrisvest:4.1-idle-state-handler

Conversation

@chrisvest

Copy link
Copy Markdown
Member

Motivation

IdleStateHandler exposes two programmatic reset methods — resetWriteTimeout() and resetReadTimeout() — intended to let callers defer idle detection without performing an actual write or read. Their documented contract is to restart the
idle timer from the point of the call.

Both methods update the relevant timestamp but do not reset the corresponding "first event" flags (firstWriterIdleEvent / firstReaderIdleEvent). As a result, if a non-first idle event has already fired before the programmatic reset, the
next idle event after the reset is incorrectly reported as WRITER_IDLE_STATE_EVENT/ READER_IDLE_STATE_EVENT (first=false) instead of FIRST_WRITER_IDLE_STATE_EVENT/
FIRST_READER_IDLE_STATE_EVENT.

This is inconsistent with the writeListener path, which resets both the timestamp
and the first-event flags together.

Modifications

  • resetWriteTimeout(): add firstWriterIdleEvent = firstAllIdleEvent = true
  • resetReadTimeout(): add firstReaderIdleEvent = firstAllIdleEvent = true
  • Add IdleStateHandlerResetFlagTest with two tests that exercise the post-non-first-event reset sequence for both methods

Result

After calling resetWriteTimeout() or resetReadTimeout(), the next idle event correctly fires as FIRST_WRITER_IDLE_STATE_EVENT or FIRST_READER_IDLE_STATE_EVENT,consistent with what a real write or read activity would produce.


Note: the same issue exists in the 4.1 branch. Happy to provide a backport if the team considers it in scope.

Signed-off-by: husseinvr97 [email protected]

(cherry picked from commit 512ba9d)

…out/resetReadTimeout (netty#16982)

## Motivation

`IdleStateHandler `exposes two programmatic reset methods —
`resetWriteTimeout()` and `resetReadTimeout()` — intended to let callers
defer idle detection without performing an actual write or read. Their
documented contract is to restart the
idle timer from the point of the call.

Both methods update the relevant timestamp but do not reset the
corresponding "first event" flags (firstWriterIdleEvent /
firstReaderIdleEvent). As a result, if a non-first idle event has
already fired before the programmatic reset, the
next idle event after the reset is incorrectly reported as
`WRITER_IDLE_STATE_EVENT`/ `READER_IDLE_STATE_EVENT` (first=false)
instead of `FIRST_WRITER_IDLE_STATE_EVENT`/
`FIRST_READER_IDLE_STATE_EVENT`.

This is inconsistent with the writeListener path, which resets both the
timestamp
and the first-event flags together.

## Modifications

- resetWriteTimeout(): add `firstWriterIdleEvent = firstAllIdleEvent =
true`
- resetReadTimeout(): add `firstReaderIdleEvent = firstAllIdleEvent =
true`
- Add IdleStateHandlerResetFlagTest with two tests that exercise the
  post-non-first-event reset sequence for both methods

## Result

After calling `resetWriteTimeout()` or `resetReadTimeout()`, the next
idle event correctly fires as `FIRST_WRITER_IDLE_STATE_EVENT `or
`FIRST_READER_IDLE_STATE_EVENT`,consistent with what a real write or
read activity would produce.

---
Note: the same issue exists in the 4.1 branch. Happy to provide a
backport if the team considers it in scope.

Signed-off-by: husseinvr97 <[email protected]>

(cherry picked from commit 512ba9d)
In 4.1 the time-freeze in EmbeddedChannel is not as advanced as in 4.2, so we actually need to sleep for the duration we advance time by.
@chrisvest
chrisvest merged commit 4e7dc11 into netty:4.1 Jun 25, 2026
18 checks passed
lltopk pushed a commit to lltopk/netty that referenced this pull request Oct 24, 2026
…out/resetReadTimeout (netty#16982) (netty#16989)

## Motivation

`IdleStateHandler `exposes two programmatic reset methods —
`resetWriteTimeout()` and `resetReadTimeout()` — intended to let callers
defer idle detection without performing an actual write or read. Their
documented contract is to restart the
idle timer from the point of the call.

Both methods update the relevant timestamp but do not reset the
corresponding "first event" flags (firstWriterIdleEvent /
firstReaderIdleEvent). As a result, if a non-first idle event has
already fired before the programmatic reset, the
next idle event after the reset is incorrectly reported as
`WRITER_IDLE_STATE_EVENT`/ `READER_IDLE_STATE_EVENT` (first=false)
instead of `FIRST_WRITER_IDLE_STATE_EVENT`/
`FIRST_READER_IDLE_STATE_EVENT`.

This is inconsistent with the writeListener path, which resets both the
timestamp
and the first-event flags together.

## Modifications

- resetWriteTimeout(): add `firstWriterIdleEvent = firstAllIdleEvent =
true`
- resetReadTimeout(): add `firstReaderIdleEvent = firstAllIdleEvent =
true`
- Add IdleStateHandlerResetFlagTest with two tests that exercise the
post-non-first-event reset sequence for both methods

## Result

After calling `resetWriteTimeout()` or `resetReadTimeout()`, the next
idle event correctly fires as `FIRST_WRITER_IDLE_STATE_EVENT `or
`FIRST_READER_IDLE_STATE_EVENT`,consistent with what a real write or
read activity would produce.

---
Note: the same issue exists in the 4.1 branch. Happy to provide a
backport if the team considers it in scope.

Signed-off-by: husseinvr97 <[email protected]>

(cherry picked from commit 512ba9d)

Co-authored-by: husseinvr97 <[email protected]>
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