Repository navigation
Description
Search before asking
- I had searched in the issues and found no similar issues.
What happened
In the SeaTunnel Zeta engine (dev at 39c74ce48b0), when a failing pipeline enters its retry backoff sleep (job.retry.times > 0, job.retry.interval.seconds > 0) and a user calls cancelJob(jobId) during that backoff window:
cancelJob(jobId)blocks for the entire remainingjob.retry.interval.secondsduration (e.g., 6s in reproduction, or minutes in production deployments with longer retry intervals), holding both theSubPlanmonitor lock and the caller/coordinator cancellation thread.- After the backoff sleep ends, the engine ignores that the job was already canceled (
jobMaster.isNeedRestore() == false,JobStatus == CANCELING), allocates a brand-new set of slots viajobMaster.preApplyResources(this), and deploys & starts a zombie retry attempt on workers before the blockedcancelPipeline()can finally acquire the lock and tear it down.
In production, this causes:
- Unresponsive cancellation requests and thread-pool starvation when
job.retry.interval.secondsis large. - Unnecessary slot allocation and contention on clusters with tight fixed-slot capacity.
- Real side effects on external sources/sinks (connections opened, records read/written) from a zombie retry attempt launched after the user explicitly canceled the job.
Root Cause Analysis
-
SubPlan.stateProcess()holds theSubPlanintrinsic monitor lock acrossThread.sleep(...):SubPlan.stateProcess()is declaredprivate synchronized void stateProcess()(seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/dag/physical/SubPlan.java:798).- On
case FAILED:/case CANCELED:(SubPlan.java:878-885), it directly invokesprepareRestorePipeline()(SubPlan.java:609-639), which resetscurrPipelineStatustoCREATEDand then executesThread.sleep(pipelineRestoreIntervalSeconds * 1000)(SubPlan.java:628) while still holding bothsynchronized (this)andsynchronized (restoreLock). - When
cancelJob(jobId)arrives,PhysicalPlan.cancelJob()callsjobMaster.neverNeedRestore()andSubPlan.cancelPipeline(). BecausecancelPipeline()ispublic synchronized void cancelPipeline()(SubPlan.java:492), it immediately blocks onSubPlan's monitor lock for the entire remaining sleep duration and cannot interrupt or abort the pending retry.
-
No re-check of
jobMaster.isNeedRestore()or cancellation state after waking up:- Once
Thread.sleep(...)finishes,prepareRestorePipeline()unconditionally returnstrue(SubPlan.java:629). - Still inside the same
synchronizedstateProcess()invocation, lines881-883unconditionally run:jobMaster.releasePipelineResource(this); jobMaster.preApplyResources(this); restorePipeline();
restorePipeline()callsstartSubPlanStateProcess()(re-enteringsynchronized stateProcess()), driving the pipeline throughCREATED -> SCHEDULED -> DEPLOYING -> RUNNING, acquiring fresh slots from workers, and deploying all task groups for an already-canceled job.- Only after
stateProcess()returns and releases theSubPlanmonitor lock does the waitingcancelPipeline()finally run and cancel the freshly deployed tasks.
- Once
Expected Behavior
When cancelJob(jobId) is called while a pipeline is waiting in its retry backoff interval:
- The pending retry backoff should be aborted promptly (without waiting for the full
job.retry.interval.secondssleep). - The pipeline should transition cleanly to
CANCELEDwithout callingpreApplyResourcesor deploying any further retry attempt (extraSlotsAllocatedAfterCancel == 0).
How to Reproduce
- Start a single-node embedded Zeta cluster with fixed slots (
dynamic-slot: false,slot-num: 10). - Submit a failing batch job with
job.retry.times = 3andjob.retry.interval.seconds = 6(for example, aFakeSource-> failing SQL castselect cast(name as int) as name, id from fake->Consolejob). - Wait until attempt 1 fails and pipeline 1 enters
prepareRestorePipeline()backoff sleep (subPlan.getPipelineRestoreNum() == 1 && subPlan.getCurrPipelineStatus() == PipelineStatus.CREATED). - Record
slotReqBefore = server.getSlotService().getSlotMetrics().getSlotRequestSuccessTotal()(equals2for 1 coordinator + 1 task group). - Call
client.cancelJob(jobId)and measure elapsed time untilcancelJob(jobId)returns and the job terminates. - Observe the actual runtime output:
cancelJob(jobId)blocks for~6100-6200 ms(the entire 6-second retry backoff interval).slotRequestSuccessTotalincreases from2to4(extraSlotsAllocatedAfterCancel == 2), proving that aftercancelJobwas invoked andneedRestorebecamefalse, the waking retry path still allocated fresh slots and deployed a zombie attempt fixed ConfigBuilder.scala #2 before cancellation took effect.
Suggested Fix Direction
- Do not hold the
SubPlanmonitor lock across the retry backoff sleep:- Replace the in-lock
Thread.sleep(pipelineRestoreIntervalSeconds * 1000)with a cancellable scheduled delay (e.g.,ScheduledFuture<?>or interruptible wait outsidesynchronized (this)) thatcancelPipeline()/forceStopPipeline()immediately cancels/interrupts.
- Replace the in-lock
- Re-check
jobMaster.isNeedRestore()and cancellation state before allocating resources or redeploying:- After the backoff completes (and before
jobMaster.preApplyResources(this)andrestorePipeline()), re-verifyjobMaster.isNeedRestore()and that the job/pipeline is not being canceled/stopped. If canceled, completesubPlanDone(PipelineStatus.CANCELED)andpipelineFuturedirectly with zero extra slot requests.
- After the backoff completes (and before
- Add regression tests:
- Add a unit/E2E test canceling a failing job during
job.retry.interval.seconds(e.g., 6s) and asserting both prompt cancellation (<< retry interval) andslotRequestSuccessTotalremaining unchanged aftercancelJob(extraSlotsAllocatedAfterCancel == 0).
- Add a unit/E2E test canceling a failing job during
Call for Contributors
This is a clean, well-reproducible Zeta engine state-machine bug with high practical impact for production cancellation responsiveness and slot hygiene. Community contributors are very welcome to claim and fix this issue! Feel free to leave a comment below if you'd like to take it on or discuss the cancellation-safe backoff design.
SeaTunnel Version
dev (39c74ce48b0)
Are you willing to submit a PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
CryoThrust commentedon Nov 27, 2026
There are two related boundaries here, and I would coordinate with #12510 before implementing this issue.
On current dev
39c74ce48,stateProcess()holds the SubPlan monitor whileprepareRestorePipeline()sleeps insiderestoreLock.cancelPipeline()needs the same SubPlan monitor. That supports the reported cancellation-latency problem independently of whether a retry is eventually allowed to allocate resources. I have checked the source path, not rerun the embedded reproduction yet.#12510 already adds
isNeedRestore()checks before and afterpreApplyResources, including release of reservations completed after cancellation. I would not duplicate that resource-allocation fix. Its current patch does not change the in-monitor retry sleep, so promptly waking a pending backoff remains a separate piece.I would be interested in taking that backoff-only piece, coordinated with @hutiefang76's existing work. The acceptance boundary would be: cancellation during a nonzero retry interval returns promptly, no delayed continuation resets or deploys a cancelled pipeline, the normal retry delay/budget is unchanged, and existing failure/resource cleanup behavior stays intact. Tests should cover both cancellation before the wait is installed and cancellation while waiting, plus normal retry and force-stop controls; the embedded case should also keep the slot counter unchanged.
Would a separate, coordinated cancellation-wakeup change be useful here? I would keep the allocation checks owned by #12510 rather than open a competing implementation. No source change or new runtime result is claimed by this comment.
hutiefang76 commentedon Nov 27, 2026
@CryoThrust That split works for #12510. Its current head,
32cfc2e84145a2c46d976c1c3553f2bdd1aececc, checks cancellation before and after resource allocation and releases reservations completed after cancellation. It does not replace the retry sleep inside the SubPlan monitor.A separate backoff-only change would address the remaining cancellation latency without duplicating those allocation checks. Please keep the normal retry interval/budget and existing cleanup behavior intact, and include the before-wait, during-wait, normal-retry and force-stop controls you outlined. The final scope and acceptance still need maintainer confirmation. I will keep #12510 focused on its existing resource-allocation scope.