ISSUE DESCRIPTION WebServer Idle timeout task lifecycle Part of #11854. Scope Idle…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
Assistant
Now let's make the edits. First, add fields for the timer and idle timeout handler.
Assistant
Now add the volatile field for the handler and update the constructor body:
Assistant
Now let's update the constructor's tail to store the timer field and remove the eager idle timeout handler creation:
Assistant
Now remove the eager creation from constructor, moving it into startIt():
Assistant
Now let's find
startItto add the idle timeout handler start, andstopResources/suspendForCheckpointandrollbackFailedStartfor cancellation.Assistant
Now let's add the idle timeout handler start right after
running = true;:Assistant
No tabs, looks identical. Let me try using
editcommand with line numbers instead.Assistant
Now let's use edit with exact line range 426:426.
Assistant
Now let's add
cancelIdleTimeoutHandlercall torollbackFailedStart:Assistant
Now let's add
startIdleTimeoutHandler()andcancelIdleTimeoutHandler()helper methods. Let's findcloseServerSocketForStoparea to add near it, and also updatestopResources()andsuspendForCheckpoint().Assistant
Now add
cancelIdleTimeoutHandler()call at the start ofstopResources()andsuspendForCheckpoint():Assistant
Good, that worked. Now let's add cancellation to
suspendForCheckpoint():Assistant
There's a duplicate comment line now ("// Stop listening for connections" appears twice). Let's fix that.
Assistant
Good, fixed. Now let's add the
startIdleTimeoutHandler()andcancelIdleTimeoutHandler()methods. Let's place them nearcloseServerSocketForStopor afterstartIt.Assistant
Now, let's update
IdleTimeoutHandlerto add anisCancelled()hook for testing and to makecancel()override tracked (idempotent-safe already via TimerTask semantics, but let's add the test seam).Assistant
Now let's add a package-private test seam accessor in
ServerListenerto expose the current idle timeout handler for tests.Assistant
I'll add a similar accessor
listenerIdleTimeoutHandlerinLoomServerfor test use.Assistant
Now let's build to check everything compiles.
Assistant
Pre-existing environment issue, not related to my changes. Let's check for release version config and possibly override it via mvn property.
Assistant
Compilation succeeded (no ERROR lines). Let's verify with explicit BUILD SUCCESS.
Assistant
Now let's compile test-sources and run existing tests related to ServerListener lifecycle.
Assistant
Now let's run the two existing test classes.
Assistant
All existing tests pass. Now let's write a focused test for idle timeout lifecycle. First examine how
WebServer.builder()exposes internals, and how test can accessLoomServermethods (package-private, so test must be in same package).Assistant
Now let's create the test file.
Assistant
All 3 tests pass. Now let's run the full test suite of the webserver module to make sure nothing else broke.
Assistant
All 129 tests pass. Let's view the final diff for review.
Assistant
No other usages elsewhere. Let's also run the full webserver module tests once more and check checkstyle/spotbugs if configured (quick check).
Assistant
Checkstyle passes cleanly. Let's do a final full test run for the module once more to be safe, then review the whole diff again.
Assistant
All good. Let's review the checklist items.
Checklist review:
Assistant
Now going through the checklist:
- If an error was reported in the issue description, I have successfully reproduced it. — This issue is a feature/lifecycle-hardening request rather than a reported runtime error/exception. There was no crash to reproduce; instead I confirmed the gap described (idle timeout handler was a local variable in
ServerListener's constructor, never retained, never cancelled on stop/suspend) by reading the code, which matched the issue description exactly.
- If an error was reported in the issue description, I have successfully reproduced it. — This issue is a feature/lifecycle-hardening request rather than a reported runtime error/exception. There was no crash to reproduce; instead I confirmed the gap described (idle timeout handler was a local variable in
Assistant
This confirms the full, focused change. Let me go through the checklist explicitly now:
Assistant
All relevant tests pass. Summary of the checklist:
- Reproduced reported error: This issue describes a lifecycle/design gap (not an exception), which I confirmed by reading the pre-change code —
IdleTimeoutHandlerwas a local variable in the constructor with no field retention and no cancellation hooks, exactly as described. - Confirmed fix resolves it: Added
ServerListenerIdleTimeoutTestwith 3 focused tests (stop cancels, suspend cancels + resume restarts a fresh task, repeated stop stays idempotent) using an explicitisCancelled()hook onIdleTimeoutHandlerinstead of real-time timer waits — all pass. - Edge cases considered: startup-failure rollback path also cancels the handler;
resume()creates a brand-newIdleTimeoutHandler(since a cancelledTimerTaskcan't be rescheduled); cancellation is guarded by a null check plus relies onTimerTask.cancel()'s own idempotency, and is also tracked via anAtomicBooleanfor test observability. - Existing tests run and pass: Full
webserver/webservermodule test suite (129 tests) plus checkstyle all pass with no regressions.
- Reproduced reported error: This issue describes a lifecycle/design gap (not an exception), which I confirmed by reading the pre-change code —
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.