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
Let me start by exploring the repository structure to understand the codebase.
Assistant
Let me look at the ServerListener.java file first.
Assistant
Let me look at the IdleTimeoutHandler class:
Assistant
Now I have a good understanding. Let me look at the full ServerListener.java to understand all lifecycle methods better:
Assistant
Now I have a complete understanding. Let me also check the LoomServer.java to see if anything else needs to bedone:
Assistant
Let me look at the test file structure more carefully to understand patterns being used:
Assistant
Now let me check the existingtest file structure and look at LoomServer to understand the lifecycle:
Assistant
Let me look at the ListenerConfig to understand what
idleConnectionTimeoutandidleConnectionPeriodare:Assistant
Now let me look at the existing tests and understand what test setup is needed. Let me look at ServerListenerLifecycleTest more carefully:
Assistant
Now let me look at the
listenerThreadStatemethod:Assistant
Let me also check the existing pom.xml to know how to build:
Assistant
Now I have enough context. Let me make a plan:
Plan:
- Modify
ServerListener.javato retain theIdleTimeoutHandleras a field. - Modify the
stop(),suspend(), androllbackFailedStart()methods to cancel the timeout task. - Ensure idempotency so repeated calls don't fail.
- Move the
start()of the timeout task to the listener's actual start, not the constructor. - Add tests for the new behavior.
Let me first look at how the listener lifecycle works again and how the start() flow happens:
- Modify
Assistant
Now I have a comprehensive understanding. Let me plan my changes and then implement them.
Assistant
Let me also look at how LoomServer.stop() works and check the listenerThreadState method:
Assistant
Let me also check the test patterns for setting up a server to understand the conventions:
Assistant
Let me check how listeners are exposed for tests:
Assistant
Now I have a complete understanding. Let me also verify by looking at one more file - the WebServerConfig:
Assistant
Let me also check if there are ways to access the ServerListener from the WebServer (for tests):
Assistant
Now I have a complete understanding. Let me start implementing the changes. First, let me modify
IdleTimeoutHandler.java:Assistant
Now let me modify the
IdleTimeoutHandler.javato addcancel()andisCancelled():Assistant
Now let me modify the
ServerListener.java:Assistant
Now let me modify the
ServerListener.java. First, let me look at the field declarations:Assistant
Let me now make the first change - add the
idleConnectionTimerfield and theidleTimeoutHandlerfield:Assistant
Let me try using sed to do the edit instead:
Assistant
Now let me add the
idleTimeoutHandlerfield:Assistant
Now let me look at the constructor part where the IdleTimeoutHandler is created and modify it:
Assistant
Now let me remove the duplicate IdleTimeoutHandler creation:
Assistant
Let me clean up the extra blank line:
Assistant
Now let me look at the start() method and the stop()/suspend()/rollbackFailedStart() to add the lifecycle hooks:
Assistant
Now let me add a getter for
idleTimeoutHandlerand the cancel method. Let me modify thestop()method to cancel the timeout task:Assistant
Now let me modify the
stop()method to cancel the idle timeout task:Assistant
Now let me modify the
suspendForCheckpoint()method to cancel the idle timeout task:Assistant
Now let me modify the
rollbackFailedStart()method to cancel the idle timeout task:Assistant
Let me use a different approach - use a Python script for the multiline replacement:
Assistant
Now let me modify the
startIt()method to start the idle timeout task:Assistant
Now I need to add the
cancelIdleTimeout(),scheduleIdleTimeout(), and the getter methods. Let me find a good place to add them:Assistant
Let me add the helper methods after
rollbackFailedStartand beforesuppressCleanupFailure:Assistant
Let me view the full updated file to verify it's correct:
Assistant
I see there's a missing closing brace. Let me fix it:
Assistant
Let me fix this - I added an extra
);line. Let me clean it up:Assistant
Let me look at the file more carefully:
Assistant
Let me look at the lines around 188-195 carefully and fix the structure:
Assistant
Now let me add a blank line between
}and@Override:Assistant
Now let me verify the complete structure by checking the git diff once more:
Assistant
I see there's an issue - let me add back the blank line:
Assistant
Let me verify the final diff:
Assistant
The diff looks good. Now let me also add the test seam on
LoomServerto expose the listener's idle timeout handler for tests:Assistant
Let me fix the duplicate line:
Assistant
Let me revert LoomServer.java to start fresh:
Assistant
Now let me carefully use sed to add a method:
Assistant
Now let me verify the diff:
Assistant
Now let me try to compile to make sure my changes are syntactically valid:
Assistant
The project requires Java 26 but we have Java 25. Let me check if we can use Java 25 source/target:
Assistant
The project requires Java 26 but we only have Java 25. Let me try to compile with Java 25 target by overriding the property:
Assistant
Let me fix the visibility issue first and check the field declaration:
Assistant
I forgot to declare the
idleConnectionTimerfield. Let me add it:Assistant
Now let me fix the visibility of
cancel()inIdleTimeoutHandler:Assistant
Let me try compiling again:
Assistant
I need to check the signature of TimerTask.cancel(). It returns boolean. Let me look:
Assistant
Let me update to return boolean to match TimerTask signature:
Assistant
Let me rewrite the IdleTimeoutHandler.java cleanly:
Assistant
Now let me try compiling again:
Assistant
Compilation succeeded. Now let me also run the test compile to make sure my changes don't break anything:
Assistant
Both compile and test-compile succeed. Now let me also write the tests for the new functionality:
Assistant
Let me write a test file for the new functionality:
Assistant
Let me try to compile the tests:
Assistant
Tests compile. Now let me run the tests to see if they pass:
Assistant
Let me look at the existing test pattern for startup failure:
Assistant
Let me update my test to expect the IllegalStateException:
Assistant
I need to add the
instanceOfimport. Letme check the current imports:Assistant
Now let me run the tests again:
Assistant
All 6 tests pass. Now let me also run the existing related tests to make sure I haven't broken anything:
Assistant
All 22 tests pass. Let me also run a broader test to make sure I haven't broken anything else:
Assistant
All 132 tests pass. Let me also think about edge cases and improve the test coverage:
- The tests I wrote cover the main cases mentioned in the issue:
stopCancelsIdleTimeoutTask: Verifies that listener stop cancels the idle timeout task.suspendCancelsIdleTimeoutTask: Verifies that listener suspend cancels the idle timeout task.repeatedStopRemainsSafeAfterIdleTimeoutCancel: Verifies repeated stop paths remain safe.suspendThenStopRemainsSafe: Verifies suspend + stop paths remain safe.startupFailureCancelsIdleTimeoutTask: Verifies startup failure cancels the task (rollback path).stopAfterCancelledTaskIsIdempotentOnHandler: Direct verification of handler-level idempotency.
Let me also think about other potential issues:
- What about the
resume()case? After suspend, resume re-starts the listener. We should verify that resume re-schedules the task.
Let me update the suspend test to also verify resume re-schedules:
- The tests I wrote cover the main cases mentioned in the issue:
Assistant
Let me also look at the complete ServerListener.java to verify the changes are correct:
Assistant
Let me also check if there are any other tests I should be running:
Assistant
Let me also verify the tests pass once more:
Assistant
Let me check what happens if
Timer.scheduleis called twice on the same task:Assistant
Let me run the test once more and check for any issues:
Assistant
Let me improve the suspend test to also verify resume creates a fresh handler:
Assistant
Let me also add a test for resume - checking that resume re-schedules the idle timeout task:
Assistant
Let me check the file:
Assistant
Let me fix the structural issues:
Assistant
Now let me run the tests:
Assistant
Wait, the errors are at line 122 and others but they show different lines. Let me view the actual file content:
Assistant
Let me check if there's some hidden character or non-UTF8 issue:
Assistant
Let me see the actual file at line 88:
Assistant
Let me see the entire file:
Assistant
I see the issue - the first suspend test is missing the closing
}. Let me fix:Assistant
Now let me run the tests:
Assistant
All 7 tests pass. Now let me run all the tests to make sure nothing is broken:
Assistant
All 133 tests pass. Let me also view the final test file:
Assistant
Let me clean up the test file by removing the more complex test:
Assistant
Let me view the diff one more time to verify everything looks good:
Assistant
Let me also verify the test file:
Assistant
All 133 tests pass. Let me also check the structure of the test file once more:
Assistant
Let me view the final test file:
Assistant
Let me also view the final state of the ServerListener.java:
Assistant
Let me also verify the IdleTimeoutHandler.java:
Assistant
Let me also run the tests one more time to confirm everything works:
Assistant
Let me also run some related tests in other modules to ensure nothing is broken:
Assistant
Let me also do a final review by viewing the diff:
Assistant
The implementation looks complete. Let me also run a final check on all tests to make sure nothing is broken:
Assistant
Assistant
Let me try the actual submitcommand:
Assistant
All my changes are in place. Let me do one more verification run:
Assistant
All 29 relevant tests pass (7 new + 21 existing lifecycle tests + 1 existing suspend test).
Now let me submit the changes:
Assistant
Let me unstage since the instructions say
submitusesgit diff(unstaged changes):
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.