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 and understanding the codebase.
Assistant
Let me see the truncated middle section of the file:
Assistant
Now let me look at how the idleConnectionTimer is created and passed to ServerListener:
Assistant
Now let me look at LoomServer to understand how the timer and listeners are managed:
Assistant
Assistant
Let me check what methods LoomServer exposes for accessing listeners:
Assistant
Now I have a clear understanding. Let me implement the changes. First, let me update
IdleTimeoutHandler.javato add cancellation tracking:Assistant
Now let me add the cancellation tracking field and methods:
Assistant
Now let me add the
cancel()override andisCancelled()method at the end:Assistant
Now let me edit
ServerListener.java. First, add the fields:Assistant
Now let me update the constructor - store the timer and remove the IdleTimeoutHandler creation/start:
Assistant
The edit broke the code - the
configuredAddresslambda closing brace was removed. Let me fix it:Assistant
There's a missing blank line between line 185 and 186. Let me fix it:
Assistant
There's a duplicate line. Let me fix it:
Assistant
There's an extra
}on line 191. Let me fix it:Assistant
Now there's a duplicate
@Overrideon lines 192-193. Let me fix:Assistant
Good, the constructor is now clean. Now let me add the
startIdleTimeoutHandler()andcancelIdleTimeoutHandler()methods and a test accessor. Let me add them nearserverThreadState():Assistant
Now let me add the cancel call in
stopResources()at the beginning:Assistant
Now let me add the cancel call in
suspendForCheckpoint():Assistant
Now let me find the end of
startIt()to add thestartIdleTimeoutHandler()call:Assistant
The edit messed up the structure. Let me view the full
startIt()method now:Assistant
The structure is broken. Let me fix the whole tail of
startIt():Assistant
Let me check the original version to restore the structure correctly:
Assistant
I see the missing
}for the else block. Let me fix lines 470-475:Assistant
Now the structure looks correct. Let me add the
cancelIdleTimeoutHandlercall inrollbackFailedStartand define the helper methods. First, let me add the cancel torollbackFailedStart:Assistant
Now let me add the
startIdleTimeoutHandler()andcancelIdleTimeoutHandler()private methods. Let me add them afterinitServerThread():Assistant
There's a missing blank line between line 332 and 333. Let me fix it:
Assistant
Now let me add the test accessor in
LoomServer.java:Assistant
Now let me verify the changes compile by reviewing the full diff:
Assistant
The diff looks good. Now let me check the build system and try to compile:
Assistant
The Java version required is 26, but the environment doesn't have it. Let me check the Java version available.
Assistant
Let me check the configured release version:
Assistant
Let me try compiling with the Java version overridden to 25 to verify syntax:
Assistant
Compilation succeeded. Let me verify the exit code and confirm:
Assistant
Compilation passes. Now let me write a test to verify the behavior. Let me first look at the existing test structure for how to access the listener state and understand
idleConnectionPeriodconfig:Assistant
Let me look at the helper methods in the existing lifecycle test to follow patterns:
Assistant
Let me look at the suspend/resume methods in LoomServer:
Assistant
Now I have enough understanding. Let me create the test file:
Assistant
Let me remove the unused
nullValueimport:Assistant
Let me check the ResumableSupport to ensure suspend works in tests:
Assistant
Now let me try to compile and run the tests. First, let me check if test dependencies resolve in offline mode:
Assistant
The surefire plugin isn't available offline. Let me try online mode to download the test runner:
Assistant
The output is truncated. Let me check the exit code and look at the surefire reports.
Assistant
All 3 tests pass. Now let me run the existing related tests to make sure I didn't break anything:
Assistant
All tests pass. Let me check for any other tests that might be affected by this change:
Assistant
Let me look at the idle connection timeout tests in the lifecycle test to ensure they exercise the new lifecycle:
Assistant
These idle timeout tests exercise the actual handler running and they passed. Let me also check if any tests construct
ServerListenerdirectly expecting constructor-time idle timeout start:Assistant
Let me check whether the shared
idleConnectionTimeris ever cancelled, which could affect the handler:Assistant
Let me add a defensive cancel of any prior handler in
startIdleTimeoutHandler()to prevent task leaks on re-start (e.g., resume without prior cancel):Assistant
I need to open the ServerListener file first:
Assistant
Let me recompile and re-run all the relevant tests to confirm everything still passes:
Assistant
All tests pass. Let me run a broader set of webserver tests to ensure nothing else is broken by the lifecycle change:
Assistant
Let me run the full webserver test suite to be thorough, but with a reasonable timeout:
Assistant
Let me look at the full test directory to understand the scope. Let me run a broader set of tests - those that involve actual server start/stop with connections. Let me run the http1 tests which actually start servers and make requests, to verify the idle timeout handler integration doesn't break real request handling.
Actually, let me just run the full webserver test suite. It's the safest. Let me check the number of test classes first.
Assistant
Let me run the full webserver test suite to be thorough:
Assistant
All 129 tests pass. Let me do a final review of all the changes:
Assistant
The changes look complete and correct. Let me verify the test file is also correct:
Assistant
Let me do a final review of the test file content:
Assistant
The finally block's if/else both do the same thing. Let me simplify it for cleanliness:
Assistant
Let me run the test one final time to confirm it still passes after the cleanup:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.