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 let me look at how
ListenerConfigandRoutercan be constructed for a direct listener test, and checkWebServer.suspend/resumevisibility. - Assistant
Now I'll implement the change in
ServerListener: - Assistant
Now add start/cancel helpers and wire them into the stop, suspend, and failed-start cleanup paths:
- Assistant
Now add the test hook next to the existing
serverThreadState()seam: - Assistant
Now write the focused test:
- Assistant
Now compile and run the tests:
- Assistant
Repo targets Java 26 but only JDK 25 is installed. Let me try overriding the release for a local test run:
- Assistant
Compiles. Now run the new test:
- Assistant
All 3 tests pass in under half a second. Now run the full module test suite to check for regressions:
- Assistant
Checkstyle passes. Let me check whether other modules exercise suspend/resume or idle-timeout behavior that could be affected:
- Assistant
That test is
@Disabledand unaffected. Let me review the final diff: - Assistant
All done. Summary of the change:
Changes
webserver/webserver/src/main/java/io/helidon/webserver/ServerListener.java- The idle timeout handler is no longer created and started as a throwaway local in the constructor. The listener now retains the
Timer(idleConnectionTimerfield) and the task itself (volatile IdleTimeoutHandler idleTimeoutHandlerfield). startIdleTimeoutTask()— called fromstartIt()(so it runs on both and ), creates a fresh each time, since a cancelled cannot be rescheduled.
- The idle timeout handler is no longer created and started as a throwaway local in the constructor. The listener now 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.