WebServer Idle timeout task lifecycle Part of #11854. Scope Idle timeout tasks should be…
- User
WebServer Idle timeout task lifecycle Part of #11854.
Scope
Idle timeout tasks should be tied to listener lifecycle and cancelled when the listener stops or suspends.
Current behavior:
webserver/webserver/src/main/java/io/helidon/webserver/ServerListener.javacreates anIdleTimeoutHandleras a local value and starts it.- The listener does not retain the timeout task.
- Stop and suspend cleanup cannot cancel the idle timeout task explicitly.
Expected behavior
- Retain the idle timeout handler or task as listener state.
- Start the task with listener startup.
- Cancel the task during listener stop and suspend cleanup.
- Make cleanup idempotent so repeated stop paths do not fail because the task was already cancelled.
Implementation notes
- Keep the change limited to idle timeout lifecycle management.
- Avoid broader timer or transport refactoring unless it is required for a focused test seam.
Tests
Add focused coverage proving:
- Listener stop cancels the idle timeout task.
- Listener suspend cancels the idle timeout task.
- Repeated stop or cleanup paths remain safe.
- The test should use a small explicit hook or test timer rather than relying on long real-time waits.
Interface
No new interfaces are introduced.
- Assistant
I'll explore the current idle timeout and listener lifecycle code, then tie task cancellation to stop/suspend with idempotent cleanup and focused tests.
- Assistant
Implementing lifecycle management: retaining the handler, starting it with the listener, and cancelling it on stop/suspend.
- Assistant
Creating the focused test class:
- Assistant
Fixing run-count tracking so tests can verify cancellation after the handler is cleared.
- Assistant
Existing lifecycle tests should still pass with the idle-timeout changes.
- Assistant
Idle timeout tasks are now tied to listener lifecycle. Summary of changes:
ServerListener- Stores
idleConnectionTimerandidleTimeoutHandleras listener state. - Starts the idle timeout in
startIt()when the listener binds (not in the constructor). - Cancels via
cancelIdleTimeout()fromstopResources(),suspendForCheckpoint(), and failed-start rollback. cancelIdleTimeout()is idempotent: it no-ops when the handler is already cleared, andIdleTimeoutHandler.cancelTask()guards repeated cancellation.- On resume, a new
IdleTimeoutHandleris created (a cancelledTimerTaskcannot be rescheduled).
IdleTimeoutHandler- Added idempotent
cancelTask()with an internal cancelled flag. - Added
runCount()for tests to observe execution without long waits.
LoomServer - Stores
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.