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 explore the webserver directory structure.
Assistant
Let me see the rest of the ServerListener.java file:
Assistant
Now let me see the IdleTimeoutHandler class:
Assistant
Now let me explore the existing tests:
Assistant
Let me look at the structureof the LoomServer class:
Assistant
Now let me check how the Timer is used elsewhere:
Assistant
Let me also look at how
WebServerandstopis implemented in theLoomServer class to understand the lifecycle:Assistant
Now I have a good understanding. Let me look at the ListenerConfig to understand the idleConnectionTimeout/Period:
Assistant
Now I have a clear picture. Let me look at what tests exist for the listener stop / suspend lifecycle:
Assistant
Now let me also examine the related tests and existing patterns:
Assistant
Let me look at all the test files for ServerListener to understand existing patterns:
Assistant
Now let me understand the test patterns more. Let me look at the existing suspend test which I can model the new test on:
Assistant
Now I have a comprehensive understanding. Let me check how
LoomServeris structured:Assistant
Now let me check what helper methods exist in tests:
Assistant
Let me look at the rest of the ServerListener.java including
startIt():Assistant
Now let me look at the listener test for the start it path more carefully:
Assistant
Let me also check the startIt method's catch block and the rollbackFailedStart to ensureI handle all cases:
Assistant
Now let me create a plan and write some temporary scripts to verify my understanding:
Assistant
Now let me look at how to test this. Let me check for ways to verify task cancellation:
Assistant
Now let me understand the current behavior by writing a small reproduction script. First, let me check the file structure once more:
Assistant
Let me look at the pom for webserver tests to see how to run a single test:
Assistant
Java 25 is too newfor the project - let me check the expected Java version:
Assistant
Java 26 is required. Let me check available Java versions:
Assistant
Java 25 is installed but Java 26 is needed. Let me see if I can install Java 26 or workwith Java 25:
Assistant
JDK 26 is not available in apt. Let me try downloading it:
Assistant
Good, got a real tarball. Let me extract it:
Assistant
Now I have JDK 26. Let me try to run an existing test to make sure the build environment works:
Assistant
Now let me implement the solution. Let me first modify
IdleTimeoutHandler.java:Assistant
Now let me modify the
IdleTimeoutHandler.javato add acancel()method andisCancelled()query:Assistant
Now let me modify
ServerListener.javato:- Store the idle timeout handler as a field.
- Start it in
startIt(). - Cancel it in cleanup paths.
- Add a method to check cancellation state.
Assistant
Now let me make the changes to
ServerListener.java:Assistant
Let me use perl for the multi-line replacement:
Assistant
Now let me modify the constructor:
Assistant
Let me verify the changes:
Assistant
Now let me add the
start()of the idle timeout handler instartIt(). Let me look at whereserverThread.start()is called:Assistant
Now I'll modify
startIt()to start the idle timeout handler just beforeserverThread.start(). Let me also be careful: iftls.newEngine()throws, the IOException catch won't catch it.Let me check the broader catch block:Assistant
Now let me start the idle timeout handler right before
serverThread.start():Assistant
Now let me add the
startIdleTimeoutTask()method andcancelIdleTimeout(). Let me look at where to add them:Assistant
Now let me add the cancellation calls in the cleanup paths. Let me look at
stopResources(),suspendForCheckpoint(), androllbackFailedStart():Assistant
Now let me modify
stopResources()to cancel the idle timeout task:Assistant
Now let me modify
suspendForCheckpoint():Assistant
Now let me modify
rollbackFailedStart()to also cancel the idle timeout task:Assistant
Let me check if there are any tests that access the listener directly:
Assistant
Let me add a similar
isIdleTimeoutTaskCancelled()method to LoomServer:Assistant
Now let me try to compile and check for any errors:
Assistant
I need to make
cancel()public to overrideTimerTask.cancel():Assistant
Hmm, the perl substitution broke the closing
*/forthe JavaDoc. Let me fix this manually:Assistant
Let me fix the broken Javadoc line:
Assistant
Now let me try to compile again:
Assistant
Compilation succeeded. Now let me view the full IdleTimeoutHandler.java to make sure it's clean:
Assistant
Let me fix the missing
@Overrideannotation:Assistant
Let me rewrite the file cleanly:
Assistant
Now let me try to compile:
Assistant
Now let me look at the full ServerListener.java to verify my changes:
Assistant
Let me view the changes in context:
Assistant
Now let me look at
startIt()to confirm we cover all paths:Assistant
Now let me check that the
resume()method also starts the idle timeout task:Assistant
Let me check what the test expects:
Assistant
Let me update the implementation to handle the resume case. I'll store the
idleConnectionTimeras a field:Assistant
Now let me update the constructor to store the timer:
Assistant
Now let me update
startIdleTimeoutTask()to recreate the task if cancelled:Assistant
Now let me compile:
Assistant
Let me review the complete changes:
Assistant
Let me first run the existing tests to make sure I haven't broken anything:
Assistant
All existing tests pass. Now let me write the new tests:
Assistant
Let me create a new test file for idle timeout task lifecycle:
Assistant
Let me look at the test file to understand the failing assertions:
Assistant
Let me look at the surefire report:
Assistant
Hmm, line 62 is
long runCountAfterStop = server.listenerIdleTimeoutTaskRunCount(WebServer.DEFAULT_SOCKET_NAME);which is an assignment, not an assertion. So the line numbers in the error must be different.Let me look at the line numbers more carefully. Wait, the error says
ServerListenerIdleTimeoutLifecycleTest.java:62but the surefire shows line 62 is the assignment. This doesn't match.Wait, maybe the error is at line 62 but from the assertion on line 62... Hmm. Let me look more carefully.
Actually wait, looking at the error message:
codejava.lang.AssertionError: Expected: is <1L> but: was <-1L>This is
Expected: 1L, was: -1L. So it's a long comparison. Let me check the test code again to see where this could be.Looking at line 62 in my test file:
javalong runCountAfterStop = server.listenerIdleTimeoutTaskRunCount(WebServer.DEFAULT_SOCKET_NAME);This is an assignment. The actual assertion is on line 63.
But the error says line 62. So maybe the line numbers are different. Let me check the file with
wc -l:Assistant
Let me update
cancelIdleTimeoutTaskto not nullify the handler, so that the run count remains accessible after cancellation. But I need to make sure the handler is recreated on resume:Assistant
Let me look at the implementation:
Assistant
Good, the implementation looks right. Let me re-compile and run the tests:
Assistant
All 5 new tests pass. Now let me also run the existing tests to ensure I haven't broken anything:
Assistant
All 131 tests pass. Let me now think about edge cases that I might have missed:
Assistant
Let me think about a few more edge cases:
Assistant
Let me write a script to verify the rollback behavior in startup failure scenarios:
Assistant
Let me verify the full implementation by looking at the full file:
Assistant
Let me also look at the other places where my changes are:
Assistant
Let me run the tests one more time to confirm all pass:
Assistant
Let me add a test for the resume case to verify the task is recreated:
Assistant
Let me use a different approach - write the file directly:
Assistant
The awk didn't insert the test. Let me check the awksyntax:
Assistant
All 6 tests pass. Let me also run the full test suite to ensure nothing else is broken:
Assistant
All 132 tests pass. Let me also run the tests in the webserver tests directory to make sure I haven't broken anything in the wider webserver tests:
Assistant
Let me look at if my changes break any other tests in the wider webserver test directory:
Assistant
Let me also check that my changes work correctly by running the full webserver test:
Assistant
All 28 listener-related tests pass. Let me also verify my code is clean by looking at the final files:
Assistant
Let me also do a final cleanup check - let me ensure there are no issues by examining my code:
Assistant
Let me also look at the test file to make sure it's clean:
Assistant
Let me fix the formatting between test methods:
Assistant
The perl substitution ate the
@Test. Let me fix this:Assistant
Let me also clean up the formatting and run the full webserver tests one more time:
Assistant
Now let me also verify the tests in the wider webserver test directory work. Let me look at what other modules depend on this:
Assistant
Let me check the spotbugs configuration:
Assistant
Build is successful. Let me also test some wider webserver tests to ensure no regression:
Assistant
Let me verify the final implementation:
Assistant
Let me fix the extra blank line:
Assistant
Hmm, the perl substitution removed
@Test. Let me checkmore carefully:Assistant
Let me see what's around line 145:
Assistant
Now let me run all tests again to make sure everything is still good:
Assistant
All 132 tests pass. Let me also test some edge cases manually using a temporary script:
Assistant
Let me also check if there are tests in other modules that might be affected:
Assistant
Let me check this test file to ensure my changes are compatible:
Assistant
This test uses
idleConnectionTimeout(Duration.ofSeconds(1))but doesn't test the lifecycle. It should still passwith my changes.Let me also check the resource-limits test:
Assistant
This test is
@Disabled. So it won't run.Let me also run the webclient tests for proxy protocol to make sure nothing is broken:
Assistant
Dependencies are not built. Let me check the webserver/webserver/ tests directory once more to ensure I haven't missed anything:
Assistant
Hmm, the
listenerStopCancelsIdleTimeoutTasktest failed. Let me look at the details:Assistant
The test has a timing issue - the Timer thread can still be executing the task when
cancel()is called. Let me make the test more robust:Assistant
Let me rewrite the file using a heredoc approach:
Assistant
All 6 tests pass. Let me also run the tests multiple times to ensure they're stable:
Assistant
All 6 tests pass consistently. Let me also run the full webserver test suite to ensure no regression:
Assistant
All 132 tests pass. Let me check the final state of my files:
Assistant
Let me also verify the implementation files:
Assistant
Let me also check that my code doesn't have any spotbugs warnings:
Assistant
Let me run spotbugs:
Assistant
No spotbugs warnings. Let me also run checkstyle:
Assistant
No checkstyle violations. Let me also check that the implementation aligns with the issue's expected behavior. Let me re-read the issue:
Assistant
Let me also test the test suite once more for stability:
Assistant
All 132 tests pass. Let me also do one final check - ensure the implementation actually works for the original issue:
Assistant
The implementation is complete. Let me also check if there's an issue with the constructor logic. Looking at it, the original was:
javaIdleTimeoutHandler ith = new IdleTimeoutHandler(idleConnectionTimer, listenerConfig, this::connectionHandlers); ith.start();And now we have:
javathis.idleTimeoutHandler = new IdleTimeoutHandler(idleConnectionTimer, listenerConfig, this::connectionHandlers);The behavior is:
- Before: handler was created and started in constructor (running even if listener never started).
- After: handler is created in constructor but not started; started in
startIt()(which is called bystart()andresume()).
This is the desired behavior. Let me also look at the related tests once more to make sure my implementation works correctly:
Assistant
All tests pass. Let me also do a final verification:
Assistant
Let me also run a wider webserver test scope to verify no regression:
Assistant
All 132 tests pass. Let me make a final summary of the changes:
Assistant
Now let me go through the checklist:
Checklist Verification
-
If an error was reported in the issue description, I have successfully reproduced it.
- The issue describes that the idle timeout task is created as a local value and started immediately in the constructor, without being tied to listener lifecycle. The listener doesn't retain a reference to the task, so cleanup paths cannot cancel it. My implementation now stores the handler as listener state, starts it with
startIt(), and cancels it during stop and suspend cleanup paths.
- The issue describes that the idle timeout task is created as a local value and started immediately in the constructor, without being tied to listener lifecycle. The listener doesn't retain a reference to the task, so cleanup paths cannot cancel it. My implementation now stores the handler as listener state, starts it with
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- My implementation:
-
Assistant
All my changes look good. Let me do one final test run to make sure everything is in order:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.