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.
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.
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate the relevant file mentioned in the issue. Let's first get a high-level view.
- Assistant
Let's examine the ServerListener.java file and understand the current idle timeout implementation.
- Assistant
Let me see the full file, particularly the
start()method and thestop()method to understand the lifecycle better. - Assistant
Let me read the full file to understand the structure better.
- Assistant
Let me see the middle section of the file:
- Assistant
Now let me look at the IdleTimeoutHandler class to understand its interface.
- Assistant
Let me examine the IdleTimeoutHandler class:
- Assistant
Now I understand the issue. Let me look for existing tests related to this:
- Assistant
Let me check these test files to understand the existing test patterns.
- Assistant
Let me also check the suspend test file.
- Assistant
Let me now look at how the
TimerTask.cancel()works and check thestartIt()andstop()methods more carefully: - Assistant
Now I have a clear understanding of the code. Let me plan the implementation:
- Store
IdleTimeoutHandleras a field inServerListenerinstead of a local variable - Start the task in
startIt()instead of in the constructor (tie it to listener startup) - Cancel the task in both
stopResources()andsuspendForCheckpoint() - Make cleanup idempotent -
TimerTask.cancel()is already idempotent
Let me also check if there are any tests that exist to understand the testing patterns better:
- Store
- Assistant
Let me look at the
LoomServerclass to understand how to access theServerListenerfor testing: - Assistant
Let me also check LoomServer to see how it creates the idle timeout handler timer and passes it to ServerListener.
- Assistant
Now let me check
ListenerConfigto understandidleConnectionTimeout()andidleConnectionPeriod(): - Assistant
Let me search for ListenerConfig:
- Assistant
Let me search for ListenerConfig differently:
- Assistant
Let me look at the ListenerConfigBlueprint to understand the idle timeout configuration.
- Assistant
Let me check the ListenerConfig interface to see the exact signatures:
- Assistant
Now I have a complete understanding. Let me implement the changes:
- Store
IdleTimeoutHandleras a field inServerListener - Start the task in
startIt()instead of in the constructor (tie it to listener startup) - Cancel the task in both
stopResources()andsuspendForCheckpoint() - Make cleanup idempotent -
TimerTask.cancel()is already idempotent
Let's implement:
- Store
- Assistant
I need to open the file first.
- Assistant
Now let me make the changes. First, add the field for
idleConnectionTimerandidleTimeoutHandler: - Assistant
The edit seems to have lost the fields. Let me check the current state and fix it:
- Assistant
The edit lost the fields. Let me restore the file and redo the edits properly:
- Assistant
Good, now let me open the file and make the edits properly with heredoc syntax:
- Assistant
Let me make the edits properly now. First, add the
idleConnectionTimerandidleTimeoutHandlerfields: - Assistant
I see there's a duplicate
private volatile boolean running;line. Let me fix that: - Assistant
Let me restore the file and start over more carefully:
- Assistant
Let me use a different approach with
sedto make targeted edits: - Assistant
Let me write a script to apply all the changes:
- Assistant
Let me try with python or use sed instead.
- Assistant
Let me use the edit command carefully with heredoc syntax. First let me open the file:
- Assistant
Let me use perl to apply all the changes in one go:
- Assistant
Let me fix the regex escaping:
- Assistant
The file was already clean. Let me use sed carefully with a script file:
- Assistant
Good, the fields are added. Let me check the constructor section:
- Assistant
Now let me replace the constructor code to store the timer instead of starting the handler:
- Assistant
Good. Now let me find the
startIt()method to add the idle timeout handler start afterrunning = true;: - Assistant
Let me see the context around line 426:
- Assistant
Now I need to add the idle timeout handler start after
running = true;. Let me add it: - Assistant
Good. Now I need to find the
stopResources()method and add the cancel call. Let me find it: - Assistant
Let me see the context:
- Assistant
I need to add the cancel call after
Throwable failure = null;on line 315. Let me do that: - Assistant
Good. Now I need to find the
suspendForCheckpoint()method and add the cancel call: - Assistant
Let me see the context:
- Assistant
I need to add the cancel call after
Throwable failure = null;on line 369: - Assistant
Good. Now I need to find the
rollbackFailedStart()method and add the cancel call: - Assistant
Let me see the context:
- Assistant
I need to add the cancel call after
running = false;on line 508: - Assistant
Good. Now I need to add the
cancelIdleTimeoutHandler()andidleTimeoutHandler()methods. Let me findcloseServerSocketOnFailure(): - Assistant
Now I'll add the new methods before
closeServerSocketOnFailure(): - Assistant
I need to add a blank line between the methods. Let me fix that:
- Assistant
Now let me verify the complete changes by looking at the diff:
- Assistant
I notice I accidentally removed the
this.router = router;line. Let me fix that: - Assistant
I need to add
this.router = router;back: - Assistant
Good. Let me verify the diff again:
- Assistant
Good! Now let me check if the
IdleTimeoutHandler.cancel()method exists: - Assistant
Good -
IdleTimeoutHandlerextendsTimerTaskwhich has acancel()method. Now let me verify the file compiles: - Assistant
Let me check what Java version is available:
- Assistant
The Maven compilation is trying to use Java 26 features but we have Java 25. Let me check the pom.xml for the webserver module.
- Assistant
Let me check if there's a way to run tests:
- Assistant
Let me check the parent pom for Java version:
- Assistant
Let me check the
version.javaproperty: - Assistant
The project requires Java 26, but we have Java 25. Let me try to compile with a lower release version:
- Assistant
The code compiles successfully! Now I need to create tests. Let me first check the test directory:
- Assistant
Let me check how to access the
ServerListenerfromLoomServer: - Assistant
I need to access the
ServerListenerfromLoomServerfor testing. Let me add a package-private accessor toLoomServer: - Assistant
I see there's already a package-private test accessor pattern. Let me add a similar method for accessing the idle timeout handler:
- Assistant
I'll add a package-private accessor for the idle timeout handler right after
listenerThreadState: - Assistant
Now let me create the test file:
- Assistant
Let me check the test file was created correctly:
- Assistant
The file seems empty. Let me check and create it properly:
- Assistant
Let me use bash to write the file directly:
- Assistant
Let me check the test file:
- Assistant
Good. Now let me run the tests to verify they pass:
- Assistant
All 3 tests pass. Now let me run the existing tests to make sure I didn't break anything:
- Assistant
All 21 tests in
ServerListenerLifecycleTestpass. Let me also run theServerListenerSuspendTest: - Assistant
All tests pass. Let me run all tests in the webserver module to make sure nothing is broken:
- Assistant
All 129 tests pass (including 3 new tests). Let me verify the final diff:
- Assistant
Let me also check the untracked files:
- Assistant
Good. Let me view the complete diff to make sure everything is correct:
- Assistant
Now let me verify the test file as well:
- Assistant
All tests pass and the changes look correct. Let me verify the final state of all changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.