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.
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:
- If an error was reported in the issue description, I have successfully reproduced it.
- Assistant
I’ll inspect the listener and timeout-handler implementations, then locate relevant lifecycle tests and build configuration before making a focused change.
- Assistant
The constructor currently starts an unretained handler exactly as reported. I’ll inspect all stop/suspend/start internals and the handler’s cancellation semantics to determine whether restart needs a fresh handler or whether the existing instance can be reused.
- Assistant
Suspend/resume implies cancellation on suspend followed by restarting timeout monitoring on resume; a
TimerTaskcannot be scheduled twice, so listener state likely needs a replaceable handler created at each startup. I’ll confirm handler behavior and understand how tests instantiate listeners and timers. - Assistant
The handler wraps a shared
TimerandTimerTask.cancel()is naturally idempotent. Starting it in the constructor is earlier than listener startup and prevents proper suspend/resume lifecycle. I’ll trace listener construction and server suspend/resume order to place creation/start and cancellation correctly, including failed startup cleanup. - Assistant
I’ll inspect
LoomServerlifecycle synchronization and rollback behavior. This is important because cancellation must happen on every cleanup path without attempting to schedule a canceled task during a rollback or resume. - Assistant
I’ll implement a replaceable listener-owned handler: retain the shared timer, create/schedule a fresh
TimerTaskonly after the socket has successfully bound, cancel-and-clear it at the start of stop/suspend cleanup, and also cancel it during failed-start rollback. Clearing before cancel plusTimerTask.cancel()makes repeated cleanup safe, while fresh creation allows resume. - Assistant
Python is unavailable in this environment, so I’ll apply the same focused patch using the repository editor tooling.
- Assistant
I’ll add the timer and active task fields, retain the timer in construction, and remove constructor-time scheduling.
- Assistant
The second line-number edit shifted after the first and duplicated
closeFuturewhile displacingserverThread; I caught this in the review output. I’ll correct the field block, then finish constructor changes. - Assistant
Another shifted line range left two stale constructor lines; I’ll repair that block explicitly to restore
routerassignment and one constructor closing brace, then use text-basedreplaceoperations rather than shifting line numbers for lifecycle edits. - Assistant
The editor requires the target occurrence to be in the open window. I’ll navigate and apply each lifecycle replacement locally, reviewing each affected section.
- Assistant
The output confirms stop and rollback changes; I’ll verify all insertion points and then add the two helper methods before the generic cleanup helper.
- Assistant
All lifecycle hooks are now in the intended locations. I’ll add synchronized start/cancel helpers so a listener-thread failure racing an external lifecycle operation cannot leave a just-scheduled task uncanceled. The start helper cleans up its task if scheduling itself fails.
- Assistant
The implementation is syntactically clean. Before testing, I’ll review the complete diff for accidental edits and inspect module test commands/profile conventions.
- Assistant
The diff is limited to timeout lifecycle management. I’ll compile and run the two focused listener lifecycle/suspend test classes in the webserver module; this also exercises startup failure rollback, normal stop, suspend, resume, and final stop.
- Assistant
Testing is blocked by the default JDK being older than the repository’s required Java 26. I’ll inspect installed JDKs and, if no compatible one exists, still perform available static checks and reason through a small direct timer-task seam without modifying tests.
- Assistant
Only JDK 25 is installed. I’ll identify the release property and attempt the module build with a temporary command-line override to Java 25; if source uses no Java 26-only constructs, this can still validate the change.
- Assistant
I’ll rerun the focused build with
version.java=25, retaining all source and repository files unchanged. - Assistant
The Java 25 override build and both focused test classes passed. I’ll verify Surefire counts and add one small race guard: if stop wins after
running = truebut before scheduling, startup must not create a timeout task after cleanup. This keeps cancellation robust beyond the server-level lifecycle lock. - Assistant
The test reports confirm 22 tests passed with no failures. Since the race guard changed source afterward, I’ll rerun those tests, then run the module’s normal verification-related checks under the same Java 25 override and inspect final repository status/diff.
- Assistant
Focused tests pass again and the normal test lifecycle’s style/code-generation checks also pass. I’ll run the complete
webserver/webservermodule test suite for regression coverage. - Assistant
The complete module test suite passes. Final review: the task is absent before startup, created after successful socket bind, canceled before stop/suspend resource cleanup, recreated on resume, canceled on failed-start rollback, and cancel/clear is idempotent. I’ll inspect the final diff and status once more before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.