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 files. Let's first check the directory structure.
- Assistant
Let me find the specific ServerListener.java file mentioned in the issue.
- Assistant
Let me look at the ServerListener.java file to understand the current implementation.
- Assistant
Let me continue reading the file to see the idle timeout handler implementation.
- Assistant
Let me scroll down to see the rest of the file.
- Assistant
Let me continue reading the file to see the stop and suspend methods.
- Assistant
Let me continue reading to see the suspend method and the stopResources method.
- Assistant
Let me look at the IdleTimeoutHandler class.
- Assistant
Let me open the IdleTimeoutHandler.java file.
- Assistant
Let me see the rest of the file and understand how the
Timeris provided. - Assistant
Let me look at the rest of the ServerListener file:
- Assistant
Let me go back to the ServerListener file and read the rest of it.
- Assistant
Let me read the rest of the ServerListener file from line 180 onwards to see the idle timeout handler creation and the stop/suspend methods.
- Assistant
Now let me look at the
startItmethod andresumemore carefully: - Assistant
Let me look at the
resumemethod and check whether it restarts the idle timeout: - Assistant
Now let me check for existing tests related to ServerListener and IdleTimeoutHandler:
- Assistant
Let me look at the existing tests to understand how they work.
- Assistant
Let me look at how the Timer is created and passed to ServerListener:
- Assistant
Now let me see where the Timer is created and where ServerListener is instantiated:
- Assistant
Now I have a good understanding of the issue. Let me look at the full file to see the full structure and understand what changes need to be made:
- Assistant
Now let me look at the
startItmethod: - Assistant
Let me check how the WebServer creates ServerListener:
- Assistant
Let me look at the LoomServer class to understand how the idle timeout handler is created and how the timer is managed.
- Assistant
Now I understand the issue. Let me look at the existing suspend test to understand the patterns.
- Assistant
Now I have a good understanding of the issue. Let me plan the implementation:
-
In
ServerListener.java:- Add a field to store the
IdleTimeoutHandler - Cancel it in
stopResources()andsuspendForCheckpoint() - Re-create it in
resume()
- Add a field to store the
-
In
IdleTimeoutHandler.java:- Add an idempotent
stop()method that cancels the timer task
- Add an idempotent
-
Add tests to verify the behavior
Let me start by modifying
IdleTimeoutHandler.javato add astop()method: -
- Assistant
Now let me add the
stop()method toIdleTimeoutHandler: - Assistant
Now let me modify
ServerListener.java. First, let me see the full file to understand all the areas I need to modify: - Assistant
Now I have a clear picture. Let me make the changes to
ServerListener.java:- Add a field to store the
IdleTimeoutHandlerand theTimer - In the constructor, store the handler as a field
- In
stopResources()andsuspendForCheckpoint(), cancel the handler - In
resume(), re-create and restart the handler - In
rollbackFailedStart(), also cancel the handler
- Add a field to store the
- Assistant
Now update the constructor to store the timer and handler:
- Assistant
I see there's a duplicate closing brace. Let me fix that:
- Assistant
I see there's a duplicate
ith.start()line. Let me fix that: - Assistant
Good. Now let me modify the
suspend()method to cancel the idle timeout handler: - Assistant
I see there's a duplicate
suspend()andresume()method. Let me fix that: - Assistant
Good. Now I need to add the
cancelIdleTimeout()call instopResources()and add the helper methods. Let me addcancelIdleTimeout()tostopResources(): - Assistant
I see there's a duplicate
closeServerSocketForStop()line. Let me fix that: - Assistant
Now I need to add the
cancelIdleTimeout()andstartIdleTimeout()helper methods, and a package-private accessor for testing. Let me find a good place to add them. Let me first see the end of the file: - Assistant
Now let me add the helper methods before the closing brace:
- Assistant
I see there are duplicated lines. Let me check the current state of the file and clean it up:
- Assistant
I see there's a duplicated
throwIfCheckpointSuspendFailedmethod. Let me look at lines 735-785: - Assistant
I see the issue - there's broken duplication. Let me fix the entire section from line 738 to the end:
- Assistant
I see there's still a stray
}on line 738. Let me fix that: - Assistant
Good. Now let me also add
cancelIdleTimeout()to therollbackFailedStartmethod since if startup fails, we should clean up the idle timeout task too. Let me look at that method: - Assistant
Let me add
cancelIdleTimeout()to therollbackFailedStartmethod: - Assistant
I see a missing blank line. Let me add it:
- Assistant
I see there's a duplicate
LOGGER.log(TRACE, message);line. Let me fix that: - Assistant
Let me add a blank line between
rollbackFailedStartandsuppressCleanupFailure: - Assistant
Good. Now let me verify the file looks correct by checking the key sections. Let me try to compile it:
- Assistant
The compilation error is not related to our changes - it's a JDK version issue. Let me check the Java version.
- Assistant
Let me try compiling just the specific file:
- Assistant
Let me verify the changes manually by reading the key sections of the modified files:
- Assistant
Good. Let me verify the overall structure by checking brace count:
- Assistant
Let me use a different approach to check the brace count.
- Assistant
Good, the braces are balanced. Let me also verify the
IdleTimeoutHandler.javachanges: - Assistant
Now let me create the test file. First, let me understand the test patterns better by looking at the existing test:
- Assistant
Let me look at how the LoomServer exposes listeners and how tests access them:
- Assistant
Let me see the full listener access methods in LoomServer:
- Assistant
Let me look at how
listenerThreadStateandsuspend/resumework in LoomServer: - Assistant
Let me see how suspend/resume work in LoomServer:
- Assistant
Let me look at the suspend method in LoomServer:
- Assistant
Now I need to add a method to
LoomServerso tests can access theIdleTimeoutHandlerfor verification. Let me add a package-private method: - Assistant
Let me add a method to LoomServer that returns the IdleTimeoutHandler for a given socket name:
- Assistant
I notice there's a missing blank line between the methods. Let me fix that:
- Assistant
Good. Now let me create the test file. Let me create a focused test class that verifies the idle timeout handler lifecycle:
- Assistant
Let me check what happened:
- Assistant
The file seems empty. Let me write it properly:
- Assistant
Let me verify the test file was created correctly:
- Assistant
Good. Now let me check if the
idleConnectionTimeoutandidleConnectionPeriodmethods exist on theWebServer.builder(): - Assistant
Let me check if these are available on the WebServer builder:
- Assistant
The
idleConnectionTimeoutandidleConnectionPeriodare on the ListenerConfig, not the WebServerConfig. I need to set them on the listener configuration. Let me check how the existing test configures the server: - Assistant
Let me look at how the existing test uses these methods:
- Assistant
Good, the methods are available on the
WebServer.builder(). Let me verify the test file: - Assistant
Now let me check the
WebServer.DEFAULT_SOCKET_NAMEconstant exists: - Assistant
Good. Now let me also verify that the
isRunning()method exists on the server: - Assistant
Good. Now let me also verify that the
suspend()method exists on WebServer: - Assistant
Let me search for suspend/resume on the WebServer interface:
- Assistant
Let me check if
suspend()andresume()are on theLoomServer: - Assistant
Let me check if
suspend()andresume()are defined in theWebServerinterface: - Assistant
The suspend/resume methods are on
LoomServernotWebServer. Let me check if it's accessible fromLoomServer: - Assistant
Good, it has
@Overrideso it's implementing an interface method. Let me check what interface: - Assistant
Good. Now let me verify the test compiles. First, let me check if there are issues with the test - for instance, when we call
server.stop()aftersuspend(), we need to make surestop()handles the already-suspended state correctly. Let me check: - Assistant
Good. Now let me think about the test scenarios. The
stop()method inServerListenerhas a guardif (!running && !inCheckpoint) return;. Aftersuspend(),inCheckpoint = true, sostop()will still proceed. That's correct.Let me now check if calling
stop()on a LoomServer that's already stopped works properly: - Assistant
Let me check the stop method of LoomServer:
- Assistant
Let me verify the
idleConnectionTimeoutandidleConnectionPeriodare available on the WebServer builder: - Assistant
Let me check how the existing test at line 595 uses these methods on the WebServer builder:
- Assistant
Let me check the WebServerConfigBlueprint to see if it extends ListenerConfig:
- Assistant
Let me check if WebServerConfigBlueprint extends ListenerConfig:
- Assistant
Good,
WebServerConfigBlueprint extends ListenerConfigBlueprint- soidleConnectionTimeout()andidleConnectionPeriod()are inherited. Now let me try to run the existing tests to make sure we haven't broken anything: - Assistant
The build fails because of a JDK version mismatch. Let me check the project's build configuration:
- Assistant
Let me check if the issue is with a specific parent pom or module.
- Assistant
Let me check how the project is configured to find the compiler settings.
- Assistant
The project requires Java 26 but we have Java 25. Let me check if there's a way to override this.
- Assistant
The project requires Java 26, but we have Java 25. Let me try overriding the version.java property:
- Assistant
Let me try to compile just the webserver module directly:
- Assistant
Let me check if there's a pre-built version:
- Assistant
The project can't be compiled on Java 25. Let me do a final review of all changes. Let me verify the final state of the ServerListener file:
- Assistant
Let me verify the stop/suspend/resume sections and the new helper methods:
- Assistant
Let me see the helper methods at the end:
- Assistant
The implementation looks clean. Let me now review the changes I've made and go through the checklist:
Changes summary:
IdleTimeoutHandler.java: Addedstop()method that wrapscancel()(idempotent)ServerListener.java:- Added
idleTimeoutHandler(volatile) andidleConnectionTimer(final) fields - Store the handler reference in constructor
suspend()callscancelIdleTimeout()before cleanupresume()callsstartIdleTimeout()to recreate the handlerstopResources()callscancelIdleTimeout()firstrollbackFailedStart()callscancelIdleTimeout()- Added
cancelIdleTimeout(),startIdleTimeout(), andidleTimeoutHandler()accessor
- Added
LoomServer.java: AddedidleTimeoutHandler()accessor for testsServerListenerIdleTimeoutTest.java: New test file with 4 test methods
Now let me verify the final state of all changed files:
- Assistant
Let me see the full diff:
- Assistant
I notice the diff removed a blank line in
stopResources(). Let me fix that: - Assistant
I see there's a duplicate
try {and missingThrowable failure = null;. Let me fix that: - Assistant
Good. Let me check the final diff to make sure it's clean:
- Assistant
The diff looks clean and minimal. Let me also check the new test file:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.