ISSUE DESCRIPTION Woodpecker services appear to be running on UI & API after pipeline…
- User
ISSUE DESCRIPTION
Woodpecker services appear to be running on UI & API after pipeline completes
Component
server
Describe the bug
Some regression with newer releases (3.14.x) With kubernetes backend and pipelines defining services, the services are not cleaned properly. The pods from kubernetes backend are destroyed properly, but the woodpecker API still show these steps as state=running.
These are only cleaned after the pipeline times out. This prevents timely deploys as pipeline executions are not getting green status (although, as a mitigation, the pipeline waiting services can be cancelled, after which the deploy can be made).
Steps to reproduce
- Install woodpecker next-d05c597374
- Use kubernetes backend
- Define pipeline with services running infinitely, like running postgres
services: - name: postgres image: public.ecr.aws/docker/library/postgres:16-alpine3.21 ports: - 5432 environment: POSTGRES_PASSWORD: somepass POSTGRES_USER: someuser POSTGRES_DB: somedb steps: - name: wait-for-postgres image: public.ecr.aws/docker/library/postgres:16-alpine3.21 environment: DB_HOST: postgres DB_PORT: 5432 MAX_WAIT: 60 commands: - ./scripts/wait-for-postgres.sh- Run the pipeline, observe pods start for the service and the step
- once wait-for-postgres step completes, the pods are destroyed, but API still shows the service as running, also visible on Web UI.
pr-build > clone (#2): Step: clone Started: 1779195580 Stopped: 1779195594 Type: clone State: success pr-build > postgres (#3): Step: postgres Started: 1779195594 Stopped: 0 Type: service State: running pr-build > wait-for-postgres (#4): Step: wait-for-postgres Started: 1779195596 Stopped: 1779195602 Type: commands State: successExpected behavior
Pipeline services are stopped once the pipeline steps complete, the pipeline completes.
System Info
next-d05c597374 kubernetes backend, bitbucket datacenter forgeAdditional context
No response
Validations
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Assistant
I’ll trace service lifecycle handling from backend execution through server status updates, identify the regression, then add a focused source fix and run the relevant existing tests. First I’ll inspect the repository structure and recent service-related code/history.
- Assistant
The initial search shows statuses are persisted by server RPC, so the likely failure is that the agent no longer emits a terminal update for long-running service steps during teardown. I’ll locate service start/stop and step update calls, and inspect recent commits around those paths.
- Assistant
A very recent commit, “Fix workflow hang on services,” directly targets this area and the runtime tests already assert service terminal traces. I’ll inspect that change and the current runtime orchestration to determine whether Kubernetes teardown returns a state shape that bypasses the new logic.
- Assistant
Current
Rundestroys the workflow and then waits for detachedWaitStepgoroutines to report completion. That contract only works ifDestroyWorkflowcauses every backendWaitStepto return a non-nil terminal state. I’ll compare Kubernetes with Docker and inspect context usage; deleting Kubernetes resources may makeWaitStepreturn an error with a nil state, whichtraceStepcurrently interprets as a start failure but should still Exited true actually. Yet issue no trace perhaps Wait blocks due watcher. - Assistant
The key ordering is problematic for Kubernetes:
completeStepwaits for log EOF before callingWaitStep; workflow deletion can close logs, but KubernetesWaitStepthen tries to fetch/watch an already-deleted pod. I need inspect exact implementation and tests/mocks to reproduce this backend contract deterministically without changing tests. - Assistant
I need the omitted
WaitStepbody and Kubernetes pod watcher helpers. The likely robust fix belongs in runtime: detached services should be explicitly marked stopped after workflow teardown rather than depending on querying a deleted resource. But we must avoid double traces and preserve service failures that occur naturally, so I’ll understand the backend return semantics and runtime synchronization before choosing that design. - Assistant
The regression is now reproduced at code level: Kubernetes
WaitStepregisters onlyUpdateFunc.DestroyWorkflowdeletes the running service pod; deletion emits a delete event, never closesfinished, and the detached goroutine never traces or allowsRunto finish. The fix should teachWaitStepto handle deletion. For intentional teardown, a deleted running service should yieldExited: trueand exit code 0; for unexpected deletion this currently cannot be distinguished inside the backend. A better general solution is runtime cancellation signaling before deletion, but the runtime context (r.ctx) is also used to detect user cancellation and would mark services canceled. I’ll inspect runtime cancellation ownership and tracer mapping to select clean semantics. - Assistant
A Kubernetes-local fix is appropriately scoped: add a delete handler and return an exited state when the watched pod is removed. This models
DestroyWorkflow’s documented backend contract (“destroy steps still running”) and gives the runtime the terminal trace it awaits. I’ll implement tombstone-safe delete matching (Kubernetes informers may provide either a Pod orDeletedFinalStateUnknown), then run formatting, Kubernetes tests, and runtime tests. Since test modification is prohibited, verification will use existing tests plus, if needed, a temporary standalone harness that is removed afterward. - Assistant
The implementation now unblocks
WaitStepon direct and tombstone deletion events and returnsExited: true, which makes the agent sendFinishedand lets server finalize the service and pipeline. I’ll run the focused backend and runtime suites. - Assistant
Tests cannot start because this environment has neither
GOMODCACHEnorGOPATHconfigured; that is infrastructure rather than a code failure. I’ll supply a temporary external Go cache path (without modifying the repository) and rerun. - Assistant
Dependency resolution succeeded, but Go also requires
GOCACHEbecauseHOMEis unset. I’ll provide that external cache as well and rerun the same suites. - Assistant
The focused suites pass, but reviewing the actual timing reveals an important edge case: runtime starts
WaitSteponly after log draining. Kubernetes deletion may already be complete before the informer starts, in which case no delete event will arrive. I’ll harden the fix by waiting for informer cache synchronization and checking pod existence after handlers are active. I’ll also processAddFunc, which fixes the analogous case where an already-terminal pod appears in the informer’s initial list. This closes both pre-registration and registration races. - Assistant
I’ll now add Kubernetes API not-found detection, retain a concrete informer handle, process initial add events, synchronize its cache, and verify the pod still exists before blocking.
- Assistant
The race-safe implementation is in place. I’ll rerun the focused suites, then run static analysis (
go vet) for the modified package and inspect the final diff. - Assistant
Verification passes: Kubernetes backend tests, runtime package build,
go vet, and diff whitespace checks all succeed. The final change is limited to Kubernetes waiting semantics. I’ll review the exact diff once more for accidental changes and then submit.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.