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
Let me check the
LoomServertest seams and howlistenerThreadStateis exposed. - Assistant
Now let me check
LoomServer.stop()/suspend()/resume()to make sure repeated stop is safe at the server level: - Assistant
Now I'll implement the changes. First,
IdleTimeoutHandler— add idempotent cancellation state observable for tests: - Assistant
Now add the test hook to
LoomServernext tolistenerThreadState: - Assistant
Now compile and run the tests:
- Assistant
The repo targets Java 26 but only JDK 25 is installed. Let me try overriding the release for a local test run:
- Assistant
All targeted tests pass. Now run the full webserver module test suite to check for regressions:
- Assistant
Checkstyle is clean. Let me verify the copyright headers on the files I modified are current (2026):
- Assistant
All headers are current. Let me review the final diff:
- Assistant
Done. The idle timeout task is now tied to the listener lifecycle.
Changes
ServerListener.java- Retains the handler as listener state: new
idleConnectionTimerfield and avolatile IdleTimeoutHandler idleTimeoutHandlerfield; the constructor no longer creates/starts the task. - Start with listener startup:
startIt()now callsstartIdleTimeoutTask()after the listener thread starts — this covers both and . Since a cancelled can't be re-scheduled, a fresh is created on each start.
- Retains the handler as listener state: new
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.