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
Let me start by understanding the repository structure and the issue at hand. The issue is about WebServer Idle timeout task lifecycle in the Helidon project. I need to:
- Explore the relevant file:
webserver/webserver/src/main/java/io/helidon/webserver/ServerListener.java - Understand the current behavior
- Make changes to tie idle timeout tasks to listener lifecycle
- Add tests
Let me start by exploring the repository structure and the relevant file.
- Explore the relevant file:
Assistant
Let me open the file and examine it.
Assistant
Let me look at more of the file, particularly around the idle timeout handling, start, stop, and suspend methods.
Assistant
Let me look at the constructor and relevant methods more
Assistant
I need to see lines 182-195 where the IdleTimeoutHandler is created.
Assistant
Now I can see the issue. The
IdleTimeoutHandleris created as a local variable at line 184-186 and started at line 187, but never stored as a field. Let me examine thestop(),suspend(), andIdleTimeoutHandlerclassAssistant
Let me examine these key methods and the IdleTimeoutHandler class.
Assistant
Let me continue looking at stopResources and suspendForCheckpoint.
Assistant
Now let me look at the IdleTimeoutHandler class
Assistant
Let me open it.
Assistant
Now let me look at the existing tests related to the idle timeout handler.
Assistant
Let me search for existing tests related to idle timeout and ServerListener
Assistant
Let me look at the ServerListenerLifecycleTest to understand existing tests
Assistant
Let me look at the idle timeout tests in this
Assistant
Let me look at the test helper methods and other relevant infrastructure
Assistant
Let me look at how ServerListener is created and where the Timer comes
Assistant
Let me look at the LoomServer to see how the timer is created
Assistant
Let me look at the
startIt()methodAssistant
Let me look at the
startItmethod in ServerListener.Assistant
Let me look at how LoomServer handles suspend/resume
Assistant
Let me look at LoomServer suspend and resume.
Assistant
Now I have a clear picture. Let me implement the changes.
Plan:
- Add
idleTimeoutHandlerfield toServerListenerto retain the handler - Store the
idleConnectionTimeras a field for reuse on resume - Cancel the handler in
stopResources()andsuspendForCheckpoint() - Restart the handler in
startIt()(sinceTimerTask.cancel()is permanent, create a new one)
Let me first edit `ServerListener.java
- Add
Assistant
Now let me make the edits. First, add the fields:
Assistant
Good. Now update the constructor to store the timer and handler fields
Assistant
Now update the constructor section where the idle timeout handler is created
Assistant
Now let me add the cancel call in
stopResources():Assistant
Now let me add the cancelIdleTimeoutHandler call in
stopResources():Assistant
Now add cancelIdleTimeoutHandler to
suspendForCheckpoint():Assistant
Now let me add cancelIdleTimeoutHandler to
suspendForCheckpoint():Assistant
Now add startIdleTimeoutHandler call in
startIt():Assistant
Now add the private helper methods. Let me add them after
checkCancelledStartup:Assistant
Now add the helper methods:
Assistant
I see a duplicate line. Let me fix it:
Assistant
There's still a duplicate. Let me remove the extra line:
Assistant
Now let me also add cancelIdleTimeoutHandler to
rollbackFailedStartfor completeness:Assistant
Let me add cancelIdleTimeoutHandler to
rollbackFailedStart:Assistant
Now let me verify the changes compile correctly:
Assistant
Let me check the Java version and see if there's another way to compile:
Assistant
Let me check what Java version the project expects:
Assistant
Let me check the version.java property.
Assistant
Let me review the full diff of my changes:
Assistant
I see a problem! The
connectionHandlersfield was accidentally removed. Let me check and fix this:Assistant
The
connectionHandlersfield was removed! Let me fix thisAssistant
Good. Now let me verify the constructor closing brace and the rest of the file:
Assistant
The constructor's closing brace is missing! Let me fix this:
Assistant
There's a duplicate line. Let me fix it:
Assistant
There's an extra
}at line 197. Let me remove it:Assistant
There's another duplicate. Let me fix it:
Assistant
Now let me verify the full diff again:
Assistant
The diff looks good. Now let me add testing support. First, add a
cancelledtracking field toIdleTimeoutHandler:Assistant
Let me add a
cancelledtracking field toIdleTimeoutHandler:Assistant
Let me fix the duplicate and add the
cancel()override andisCancelled()method:Assistant
Let me use replace to fix the duplicate:
Assistant
Now add the
cancel()override andisCancelled()method:Assistant
Now let me add a package-private getter for the idle timeout handler in
ServerListener:Assistant
Let me add a package-private getter in ServerListener:
Assistant
Let me add a package-private getter for idleTimeoutHandler:
Assistant
There are duplicates. Let me fix them:
Assistant
Let me verify the full diff:
Assistant
Now let me look at how the test accesses the LoomServer and add tests:
Assistant
Let me look at the LoomServer class to see how listeners are accessible:
Assistant
Let me check if LoomServer's listeners field is accessible from the test:
Assistant
Let me add a package-private method to
LoomServerto expose the idle timeout handler for testing:Assistant
Let me add a package-private method to
LoomServerfor the idle timeout handler:Assistant
Let me fix the duplicate and missing closing:
Assistant
Now let me add the tests. First, let me look at the test file to understand the patterns:
Assistant
Now let me add the tests. I'll add them before the private helper methods:
Assistant
Now let me add the tests:
Assistant
There's an issue with the method signature getting cut. Let me fix it:
Assistant
Let me verify the complete diff for all changed files:
Assistant
Let me check that the test file has the needed imports:
Assistant
I need to add the
notimport. Let me check if it's already imported:Assistant
Let me add the import for
not:Assistant
There's a duplicate import. Let me fix it
Assistant
Let me verify
WebServer.DEFAULT_SOCKET_NAMEexists:Assistant
Let me check where DEFAULT_SOCKET_NAME is defined:
Assistant
Good. Let me check the LoomServer diff:
Assistant
Now let me verify the IdleTimeoutHandler diff:
Assistant
Let me try to compile with the available Java version:
Assistant
The main source compiled successfully. Let me try to compile the tests too:
Assistant
Let me see the full error output:
Assistant
These are all pre-existing errors - they exist on lines that I didn't modify. Let me verify by checking the original comp
Assistant
Wait, the original compiles fine. Let me restore my changes and check what's different:
Assistant
Let me check the specific errors more carefully:
Assistant
Let me check the exact diff of the test file:
Assistant
I see the problem! The
import static org.hamcrest.MatcherAssert.assertThat;was accidentally removed. Let me restore it:Assistant
Now let me try to compile again:
Assistant
The compilation succeeded. Now let me run the tests:
Assistant
Let me run the tests with the correct module:
Assistant
All 3 new tests pass! Now let me run all the tests in the file to make sure I didn't break anything:
Assistant
All 24 tests pass (21 original + 3 new). Let me also run the IdleTimeoutTest to make sure:Let me also run the other idle timeout test:
Assistant
Let me verify the final diff for all changes:
Assistant
The diff looks clean and all tests pass. Let me go through the checklist:
CHECKLIST REVIEW
-
✅ If an error was reported in the issue description, I have successfully reproduced it. The issue described that
IdleTimeoutHandlerwas created as a local variable and never retained, so stop/suspend couldn't cancel it. I confirmed this by reading the source code atServerListener.java:184-187. -
✅ If an error was reported in the issue description, I have confirmed that my fix resolves the error. The fix retains the
IdleTimeoutHandleras a field, cancels it duringstopResources()andsuspendForCheckpoint(), and recreates it onstartIt()(for resume after suspend). Tests confirm all three scenarios pass. -
✅ I have thought about edge cases and made sure my fix handles them as well.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.