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
Now I'll implement the changes. First,
IdleTimeoutHandler— make cancellation observable and safe: - Assistant
Now start the task in
startIt: - Assistant
Now wire cancellation into stop, suspend, and failed-start rollback:
- Assistant
Add the test accessor next to the existing test seam:
- Assistant
Now let me check
LoomServer.suspend/stopflow to make sure test sequencing (suspend → stop) works: - Assistant
Now the test file:
- Assistant
Now build and run the tests:
- Assistant
Only JDK 25 is available while the repo targets 26. I'll override the release for local verification:
- Assistant
Compiles. Now run the new test plus related lifecycle tests:
- Assistant
All 5 new tests pass. Now run the existing lifecycle/suspend/idle-related tests to check for regressions:
- Assistant
Now the full module test suite:
- Assistant
All 131 tests in the module pass. Let me check copyright headers and run the repo's checkstyle:
- Assistant
Checkstyle is clean. Final review of the diff:
- Assistant
Done. The idle timeout task is now tied to the listener lifecycle.
Changes
ServerListener.java- Retains the
Timerand avolatile IdleTimeoutHandler idleTimeoutHandleras listener state instead of creating a fire-and-forget local in the constructor. startIt(...)schedules the task only after the socket is bound, right before the listener thread starts — so both and (re)schedule it. A new handler instance is created each start, since a cancelled can't be rescheduled.
- Retains the
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.