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
I'll start by exploring the repository structure to understand the codebase.
Assistant
Let me explore the main webserver directory.
Assistant
Let me see the rest of ServerListener.java:
Assistant
Now let me see the IdleTimeoutHandler:
Assistant
Let me find existing tests for the ServerListener and IdleTimeoutHandler:
Assistant
Let me see the rest of this test file and the suspend test file to understand the patterns.
Assistant
Let me see the remaining part of ServerListener.java:
Assistant
Let me look at where the
idleConnectionTimeris created/passed in:Assistant
Now let me look at the ConnectionHandler closeIfIdle methodto understand the test seam:
Assistant
Let me look at how
Timer.cancel()works, and the existing patterns for the test seam:Assistant
Let me check the package layout:
Assistant
Let me look at the rest of ServerListener:
Assistant
Let me check the existing tests to see if there's any test that does suspend+resume with idle timeout:
Assistant
Now let me check the rest of the test file to see how the tests are set up:
Assistant
Now let me look at WebServer builder methods to understand how to add a test seam:
Assistant
Let me check if there's a way to access the listener from the WebServer:
Assistant
Let me look at the startIt() flow:
Assistant
Let me look at the rollbackFailedStart method:
Assistant
Let me check if there's a way to inject a custom timer through ListenerConfig:
Assistant
Let me check the LoomServer methods that expose listener state for tests:
Assistant
Now let me write a small reproduction script first to understand current behavior:
Assistant
Let me delete that test file and start implementing the actual changes:
Assistant
Now let me modify the
IdleTimeoutHandler.java:Assistant
Now let me modify the IdleTimeoutHandler to add cancel and isCancelled:
Assistant
Now let me modify the ServerListener.java. First, let me check the existing constructor:
Assistant
Now let me modify the constructor to assign to a field instead of starting:
Assistant
The sed replacement didn't work as expected. Let me fix it properly:
Assistant
Now let me add the field declaration:
Assistant
Now let me add the cancelIdleTimeout method and call it in stopResources() and suspendForCheckpoint(). Let me find the right location:
Assistant
Let me check the startIt() code:
Assistant
Now let me add the handler start after
serverThread.start(). I'll modify startIt() to start the handler:Assistant
Now let me add the cancel calls in stopResources() and suspendForCheckpoint():
Assistant
Now let me add the cancel call in suspendForCheckpoint():
Assistant
Now let me add a getter for the idle timeout handler for tests:
Assistant
Now let me add a getter on LoomServer for tests to access the handler:
Assistant
Now let me verify the code compiles:
Assistant
The project requires Java 26, but only Java 25 is available. Let me seeif I can override this:
Assistant
The TimerTask.cancel() is public, so we need to rename or make public. Let me use a different name:
Assistant
Now I need to update ServerListener to call cancelTask() instead of cancel():
Assistant
Now let me try to compile:
Assistant
The compilation succeeded. Now let me also verify the source code looks right:
Assistant
Let me view the ServerListener changes:
Assistant
Let me check if I need to handle the rollback case:
Assistant
Let me also add the cancel in rollbackFailedStart for safety:
Assistant
Let me try to compile:
Assistant
Now let me also try to compile the tests:
Assistant
Now let me write the tests. First let me look at the existing test file structure to find where to add new tests:
Assistant
Now let me create a new test file for the idle timeout lifecycle tests:
Assistant
The tests compile. Let me now try to run them. But first I need to check that the existing tests still pass.
Wait, I see the
Mode is failandCreated 2 META-INF/services files- let me check if these are errorsor just info messages:Assistant
The compilation succeeds. Let me now try to run the new tests:
Assistant
Let me try with online mode (the dependencies should be already downloaded):
Assistant
Let me try to find the surefire plugin or alternative way to run the tests.Let me check if there's a pre-built test setup or use mvn test directly:
Assistant
All 6 new tests pass. Now let me run the existing tests to make sure I didn't break anything:
Assistant
All 28 tests pass. Let me also run a wider set of tests to make sure nothing is broken:
Assistant
All 132 tests pass. Let me check the diff of my changes:
Assistant
Let me view the test file:
Assistant
Let me think about edge cases. Let me look at the test for suspend/resume with idle timeout:
Assistant
Let me update the code to handle resume correctly by re-creating the handler if needed:
Assistant
Let me verify the changes are correct by re-running the tests:
Assistant
Let me also run the tests in the wider webserver package to make sure nothing is broken:
Assistant
Let me check if there are any integration tests that might be affected:
Assistant
Let me look at the IdleTimeoutTest to see if it might be affected:
Assistant
This test is disabled anyway, so it won't affect my changes. Let me check the ProxyProtocolTest to see if it uses IdleTimeout:
Assistant
This test uses idleConnectionTimeout config but it doesn't directly dependon my changes. Let me also check LogService.java:
Assistant
Not related. Let me re-run all the webserver tests:
Assistant
Let me think more carefully about edge cases. Looking at the issue:
Scope
Idle timeout tasks should be tied to listener lifecycle and cancelled when the listener stops or suspends.
The scope is "tied to listener lifecycle" - which suggests restart on resume too. Let me think about whether to add resume handling. Looking at the existing tests:
Assistant
Let me update the startIdleTimeoutHandler to handle resume case by re-creating the handler if needed:
Assistant
Let me use a different approach:
Assistant
Now let me verify the changes compile:
Assistant
The issue is that
idleConnectionTimeris a constructor parameter, not a field. Let me check:Assistant
Let me revert the resume handling change since it requires more refactoring:
Assistant
Now let me recompile and rerun the tests:
Assistant
Let me also run all tests:
Assistant
All 132 tests pass. Let me check the current state of the modified files:
Assistant
Let me also verify the full ServerListener.java looks clean:
Assistant
Let me run all the tests one more time to confirm:
Assistant
Let me also see if there are tests in other webserver submodules that might be affected:
Assistant
Let me also check the test file for the tests/observe/observe tests to see if they might be affected:
Assistant
These tests are using ServerListener by name (as a logger category), not directly. So they should be unaffected.
Let me now run all tests in the wider webserver package to make sure nothing is broken:
Assistant
Can't run other module tests due to dependency issues. The webserver module itself passes all tests, so my changes are good.
Let me also verify that all my changes compile by checking the test compilation:
Assistant
Let me look at all my final changes:
Assistant
Let me also view my fulltest file to ensure it's clean:
Assistant
Let me also check the diff one more time and make sure everything is in order:
Assistant
Let me do a final verification by re-running the new tests:
Assistant
All tests pass. Let me check the final state of the implementation:
Assistant
All changes look good. Let me run all tests one final time to confirm everything works:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.