Skip to content

fix(client): TaskRunner keeps tasks leased to it at shutdown, and sends a refused update once - #195

Open
v1r3n wants to merge 2 commits into
mainfrom
fix/taskrunner-shutdown-and-refused-updates
Open

v1r3n wants to merge 2 commits into
mainfrom
fix/taskrunner-shutdown-and-refused-updates

Conversation

@v1r3n

@v1r3n v1r3n commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Three TaskRunner bugs, each shown by a test in the new TaskRunnerShutdownTest that fails on main and passes here. Nothing changes for a runner that is not shutting down, apart from the 4xx retries.

Shutdown drops the tasks of a poll in flight

shutdown shut the executor down while a poll was still on its way. The tasks the poll brought back were refused (Task rejected by executor (likely shutting down); dropping task). The server had leased them to this worker, so each waited out its response timeout before anyone else could take it.

Now shutdown waits, up to its timeout, for a poll in flight to return and its tasks to reach the executor. It does not wait through the polling interval: only the poll itself counts. A poll that is terminating the JVM on a fatal auth failure is not waited for, because System.exit waits for the shutdown hooks that call shutdown.

Tests: theTasksOfAPollInFlightWhenShutdownBeginsStillRun fails on main. shutdownDoesNotWaitForAPollLoopThatIsTerminatingTheJvm guards the fatal-auth case (it fails without the exiting flag).

With taskUpdateV2, tasks handed back at shutdown wait out their timeout

update-v2 hands back the worker's next task, already leased to it, and the poll loop picks it up from an in-memory queue. At shutdown the loop has ended, so:

  • A task finishing after shutdown began was still sent with update-v2, and the task handed back was never run. Now its result goes with updateTask, which hands nothing back.
  • A task handed back by an update already on its way when shutdown began was never run. Now it runs before shutdown returns, once the executor's tasks are done.

Tests: withUpdateV2ATaskFinishingDuringShutdownTakesNoNextTask and withUpdateV2ATaskHandedBackAsShutdownBeginsStillRuns fail on main.

A refused update is retried

retryOperation retried every failure 3 times, 2 s apart. A 4xx (a task the server no longer has, a stale or duplicate update) is refused again on every retry, and each retry holds a worker thread. Now a 4xx other than 408 and 429 is not retried. 5xx, 408, 429 and network errors are retried as before. An expired token is refreshed by TokenRefreshInterceptor before the error reaches TaskRunner, so a 401 here is final too.

Tests: aRefusedUpdateIsSentOnce fails on main. aThrottledUpdateIsRetried guards the retry that stays.

Testing

  • TaskRunnerShutdownTest: 4 of 6 fail on main, all 6 pass here.
  • ./gradlew spotlessCheck :conductor-client:test :conductor-client-spring:test :conductor-client-spring-boot4:test: 1001, 2 and 29 tests, all pass.

…ds a refused update once

- Shutdown waits for a poll in flight to return and hands its tasks to the
  executor, which still takes them. Before, the executor was shut down
  under the poll, its tasks were refused, and each waited out its response
  timeout on the server. A poll that is terminating the JVM (fatal auth) is
  not waited for: System.exit waits for the shutdown hooks.
- With taskUpdateV2, a task finishing after shutdown began is sent with
  update, which hands nothing back; a task an update handed back as
  shutdown began, which the ended poll loop no longer takes, runs before
  shutdown returns. Before, both waited out their response timeout.
- A 4xx update other than 408 or 429 is not retried: the same request is
  refused again, and each retry held a worker thread for 2 s.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant