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 start by exploring the repository structure.
Assistant
Let me see the full file, particularly the middle part that was truncated (start, suspend, stop methods).
Assistant
Now let me look at the existing tests for ServerListener to understand the test patterns.
Assistant
Let me look at how the timer is created and passed to ServerListener.
Assistant
Assistant
Now I understand the issue well. Let me check the test-access methods on LoomServer and how tests interact with the listener.
Assistant
Let me see the full
startItmethod in ServerListener.Assistant
Let me look at LoomServer stop/suspend/resume methods.
Assistant
Let me check if there are other tests that directly construct ServerListener.
Assistant
Let me check the ListenerConfig defaults for idle timeout settings.
Assistant
Now let me implement the changes. First, the
IdleTimeoutHandler.java:Assistant
There's an extra
}at the end. Let me fix it.Assistant
Now let's modify
ServerListener.java. First, add the fields and store the timer:Assistant
Now let me add the fields. I'll add the
idleConnectionTimerandidleTimeoutHandlerfields near the other volatile fields:Assistant
Now let me view the end of the constructor where the idle timeout handler is currently created and started:
Assistant
The edit introduced a duplicate
this.router = router;and an extra}. Let me fix it.Assistant
Now let me add the
cancelIdleTimeout()call instop(). Let me update the stop method:Assistant
Now let me update the
suspend()method to cancel the idle timeout task:Assistant
Now let me find the end of
startIt()to add thestartIdleTimeout()call beforeserverThread.start();:Assistant
The edit introduced some extra braces. Let me look at the current state carefully:
Assistant
I need to fix the extra braces. Let me replace lines 477-487 with the correct content:
Assistant
Now the
startIt()is correct. Now let me addcancelIdleTimeout()torollbackFailedStartfor cleanup:Assistant
Now let me add the
startIdleTimeout(),cancelIdleTimeout(), and a test accessor method. Let me find theconnectionHandlers()method:Assistant
Let me add a blank line between the methods:
Assistant
Now let me add a test accessor on
LoomServer. Let me look at the existinglistenerThreadStateaccessor:Assistant
The edit was accidentally applied to ServerListener.java (the currently open file) instead of LoomServer.java. It broke the
start()method. Let me fix this:Assistant
There are leftover duplicate lines 273-275. Let me remove them:
Assistant
ServerListener.java is now fixed. Now let me apply the LoomServer.java change using the
--fileoption:Assistant
There's a stray
}on line 276 in LoomServer.java. Let me remove it:Assistant
There's a duplicate
validateRoutingsHaveNamedListenermethod signature on lines 277-278. Let me remove the duplicate:Assistant
LoomServer.java is now correct. Let me verify the full diff of changes so far:
Assistant
The diff looks clean. Now let me write the test. First, let me check the
WebServerConfig.BuilderAPI for idle timeout settings:Assistant
The WebServerConfig might inherit from ListenerConfig. Let me check how the builder exposes idleConnectionTimeout. The IdleTimeoutTest used
builder.idleConnectionTimeout(...)andbuilder.idleConnectionPeriod(...). So the WebServerConfig.Builder has those methods. Let me confirm.Assistant
Now let me create the test file. Let me model it after the existing suspend test patterns:
Assistant
The create command didn't capture the heredoc content. Let me write the file using a shell heredoc:
Assistant
Now let me compile the webserver module to verify the changes compile. Let me check the build system:
Assistant
It's a Maven project. Let me compile the webserver module:
Assistant
The project requires Java 26 but the runtime is Java 25. Let me check available Java versions:
Assistant
Only Java 25 is available. Let me check the project's configured Java release:
Assistant
Let me try compiling with the Java version overridden to 25 just to verify my changes compile (the existing code uses Java 21+ features only):
Assistant
Main code compiles. Now let me compile the tests:
Assistant
Both main and test code compile. Now let me run the new test and the existing related tests:
Assistant
The surefire JUnit platform provider isn't available offline. Let me check the local repo:
Assistant
The surefire-junit-platform provider isn't available. The project uses surefire 3.1.0, but only 3.1.2 might be partially there. Let me check the surefire providers available.
Let me check if there's a junit-platform provider at all.
Assistant
No surefire JUnit provider is available offline. Let me check what JUnit jars are in the local repo to run the test manually:
Assistant
Let me build the test classpath using Maven's dependency plugin:
Assistant
Now let me create a standalone JUnit runner using the launcher API and run the test:
Assistant
Let me fix the JUnitRunner to use the correct API. The
registerListenermay not exist; uselauncher.execute(request, listener)instead. Let me fix.Assistant
All 3 tests pass. Now let me run the existing related tests to make sure I didn't break anything:
Assistant
All 21 tests pass (the bind exception is expected from an intentional test). Let me also check for any suspend/resume related tests that might be affected:
Assistant
Let me also check the tests/webserver module for suspend/resume tests that might be affected:
Assistant
No suspend/resume tests in the test modules. Let me do a final review of the complete diff:
Assistant
Let me do a final review of the key methods in ServerListener to confirm correctness:
Assistant
Let me run a couple more existing tests to ensure nothing is broken:
Assistant
Let me clean up the temporary runner files and verify final state:
Assistant
Now let me review the final test file to confirm it's complete:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.