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:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /helidon, current file: none) bash-$
Assistant
Now let's look at IdleTimeoutHandler.java to understand the class and its cancel mechanism.
Assistant
Let's view LoomServer.java for how ServerListener is constructed, and where the timer is created.
Assistant
Now let's add a field for the timer and the idle timeout task, plus store the timer as a field (needed in startIt).
Assistant
I'll use the
replacespecial command instead.Assistant
Now let's update the constructor to store the timer field instead of creating and starting the handler there.
Assistant
Now remove the constructor-time creation/start of the idle handler (moved to startIt):
Assistant
Now let's view suspend/resume and startIt/rollbackFailedStart/stopResources/suspendForCheckpoint sections to add hooks.
Assistant
Looks fine, no tabs. Let me try
editcommand instead using line numbers directly.Assistant
Now use
editwith explicit line range 469:473.Assistant
Now let's add
cancelIdleTimeoutHandler()calls in rollbackFailedStart, stopResources, and suspendForCheckpoint.Assistant
Now update
stopResources()andsuspendForCheckpoint().Assistant
It seems fine; let's just navigate there first then replace.
Assistant
Now let's edit both sections using
editwith line ranges directly.Assistant
Now update
suspendForCheckpoint()at line 368-372 to add cancel call.Assistant
Compiled successfully (no errors). Now let's compile test sources too and run the relevant tests.
Assistant
Good, compiles. Now let's run existing tests relevant to ServerListener lifecycle and idle timeout.
Assistant
Tests ran with no output shown but exit fine (no ERROR). Let's check surefire reports for pass/fail counts.
Assistant
All 22 tests pass. Now let's write a focused test for idle timeout task lifecycle tied to listener stop/suspend, using a small test seam. Let's check how
ServerListeneris constructed for tests and if there's direct access for test purposes.Assistant
Now add accessor to
ServerListenerandLoomServer.Assistant
Now add accessor to LoomServer near
listenerThreadState.Assistant
Now let's write the test file
ServerListenerIdleTimeoutTest.java.Assistant
Good. Now compile and run the new test.
Assistant
All 4 new tests pass. Let's temporarily verify the fix actually matters by reverting the cancel calls and confirming these tests fail (to validate test correctness), then re-apply.
Assistant
Good — confirms the tests correctly fail without the fix. Now restore the fix.
Assistant
Now let's re-run the full webserver test suite to make sure everything passes with the fix restored.
Assistant
All pass. Now let's run the full webserver module test suite to be safe (excluding possibly very slow/unrelated tests) — let's just run full test suite for this module.
Assistant
Full test suite passed (no errors). Let's check the summary counts across all surefire reports to be sure.
Assistant
Let's view the full diff for final review.
Assistant
This diff looks clean and complete. Now let's also double check checkstyle/style compliance since Helidon usually enforces checkstyle.
Assistant
No checkstyle issues. Now let's go through the checklist.
Assistant
The changes are complete and verified. Let me go through the checklist:
Checklist review:
-
If an error was reported in the issue description, I have successfully reproduced it. — The issue is a lifecycle/design gap rather than an exception. I reproduced the gap by writing tests (
ServerListenerIdleTimeoutTest) that directly assert the idle timeout task is cancelled onstop()/suspend(), then temporarily disabled thecancelIdleTimeoutHandler()calls and confirmed all 4 new tests failed as expected, proving the original code did not cancel the task on stop/suspend. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. — After restoring the fix, all 4 new tests pass, confirming stop/suspend now cancel the idle timeout task and resume starts a fresh one.
-
I have thought about edge cases and made sure my fix handles them as well. — Handled: repeated
stop()calls (idempotent, tested),suspend()/resume()cycle creating a fresh task (tested, sinceTimerTaskinstances cannot be rescheduled after cancellation), and startup-failure rollback path (rollbackFailedStart) also cancels the task defensively even though the task is only started near the very end ofstartIt(). ThecancelIdleTimeoutHandler()helper safely no-ops if the handler was never created (null-check) or already cancelled (TimerTask.cancel() is safe to call multiple times). -
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. — Ran the entire
webserver/webservermodule test suite (130 tests across 21 report files includingServerListenerLifecycleTest,ServerListenerSuspendTest, and idle-timeout-related tests inServerListenerLifecycleTest) with zero failures/errors. Also confirmed checkstyle passes.
-
Assistant
Everything looks good. Let's submit the changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →