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 look at IdleTimeoutHandler.
Assistant
Now let's check the ServerListenerSuspendTest.java for suspend-related test patterns and see how ServerListener is instantiated for direct unit tests.
Assistant
Good,
Router.empty()exists. Let's check DirectHandlers, MediaContext, ContentEncodingContext for easy defaults.Assistant
Now let's make the edits.
Assistant
No python. I'll use the
replacespecial command instead.Assistant
Now update constructor's idle handler part.
Assistant
No hidden whitespace issues visible. Let's just use
editcommand with the exact line range 184:188.Assistant
Now I'll use
editon lines 184:189.Assistant
Now let's add the test hook method near
serverThreadState(), and updatestopResources()andsuspendForCheckpoint()to cancel the idle timeout handler.Assistant
Let's use the edit command with line range instead since replace seems finicky (maybe trailing whitespace issue).
Assistant
Good. Now let's update
stopResources()to cancel idle timeout handler, andsuspendForCheckpoint()too.Assistant
Now update
suspendForCheckpoint()to also cancel idle timeout.Assistant
Now update constructor to assign field and replace inline logic with helper method call.
Assistant
Now replace lines 186-191 to call a new helper method
startIdleTimeoutHandler().Assistant
Oops, there's an extra
}(duplicate closing brace at line 189). Let me remove it.Assistant
Good, that's fixed. Now let's update
resume()and add helper methodsstartIdleTimeoutHandler()andcancelIdleTimeoutHandler().Assistant
Now let's add the two helper methods
startIdleTimeoutHandler()andcancelIdleTimeoutHandler()right afterinitServerThread().Assistant
Now let's update
IdleTimeoutHandler.javato add the cancelled tracking.Assistant
Now let's check the whole file compiles. Let's try building the webserver module.
Assistant
It's compiling now with override. Let's wait for it to complete.
Assistant
Build succeeded (exit 0). Now let's specifically compile the webserver module to confirm.
Assistant
Test compilation succeeded too. Now let's write the new test file for idle timeout lifecycle.
Assistant
Good, this is a generated blueprint so the builder should have
.idleConnectionPeriod(Duration). Let's compile the test.Assistant
Now let's actually run this test.
Assistant
Test passed (exit 0, no failures reported). Let's check surefire reports to be sure tests actually ran.
Assistant
All 4 tests passed. Now let's run the full existing ServerListener-related tests to ensure nothing broke.
Assistant
All existing tests pass. Now let's run the full webserver module test suite to be extra safe (though it may take a while).
Assistant
Full webserver module test suite passes. Let's check the summary count.
Assistant
All 130 tests pass with 0 failures/errors. Now let's also run the resource-limits idle timeout test to double check.
Assistant
Let's view the full diff for final review.
Assistant
This looks complete and clean. Let's also double check
resume()correctness - confirmstartIt()setsrunning = truebefore we callstartIdleTimeoutHandler(), which is fine either order. Let's view resume/startIt order once more and rollbackFailedStart path to ensure no issue if startIt throws before idle timeout restarted (it wouldn't restart, which is safe - listener isn't running).Assistant
This is fine —
startIt()throws if it fails, sostartIdleTimeoutHandler()won't run in that case, keeping things consistent.Now let's run the ServerListenerSuspendTest again plus a broader sanity check, and view final
ServerListener.javafile for overall correctness.Assistant
All tests pass. Let's clean up any temp files created.
Assistant
Let's do a final full diff review including the new test file content, to make sure everything is clean.
Assistant
The implementation looks complete and well-tested. Let's now go through the checklist.
Assistant
Everything looks good. Let me review the checklist explicitly before submitting:
Checklist review:
-
If an error was reported in the issue description, I have successfully reproduced it. — This issue is not a bug report with a stack trace/error, but a design gap request (idle timeout task not tied to listener lifecycle). I confirmed the gap by reading
ServerListener.java: theIdleTimeoutHandlerwas created as a local variable (), started, and never retained or cancelled anywhere in / paths — exactly as described in "Current behavior".
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.