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 first map the server/runner pipeline lifecycle code and recent service-state handling, then identify a focused reproduction through existing unit tests or a temporary test harness. After the fix, I’ll run the relevant test suites and inspect the final diff.
- Assistant
The broad search did not return matches due to the selected paths/pattern combination, so I’ll inspect the pipeline execution layout and search for step state transitions (
running,Stopped, and task completion), which should lead to where service records are finalized. - Assistant
ripgrepis unavailable in this environment. I’ll use recursivegrepand directly inspect the runtime workflow/step implementation and agent reporting code. - Assistant
The likely regression is now visible: detached services are completed in a background goroutine, while
Rundestroys the workflow before waiting for that goroutine. For Kubernetes, deleting the pod may causeTailStep/WaitStepbehavior that prevents the final trace from being sent, leaving the API record running. I’ll inspect the remainder, tests around detached ordering, backend wait/tail semantics, and recent history to determine the intended synchronization without introducing a deadlock. - Assistant
History confirms this lifecycle was recently refactored, followed by a “Fix workflow hang on services” change. I’ll compare those commits and inspect all runtime synchronization fields/tests. The key design constraint is that an infinite service cannot be waited on before teardown, but its completion trace must be emitted after teardown and before workflow completion is reported.
- Assistant
The current intended sequence is indeed “finish normal stages → destroy workflow to stop services → wait for detached completion traces.” Since that sequence already exists, the defect is likely inside detached completion: it calls per-step destruction after whole-workflow destruction. Kubernetes may return an error there, and
completeStepthen returnsnil, err; the final trace receives no exited process state, so server status logic interprets it as another running update. I’ll verify KubernetesDestroyStep/WaitStepand server state mapping, then model this backend behavior with a temporary harness or existing mocks. - Assistant
The server requires
Exited,Error, orCanceledin the final report. I’ll now inspect exact Kubernetes semantics and tracer conversion to see whether pod deletion yields a normal exited state or an error with a usable state, and whether the failure occurs before or afterDestroyStep. - Assistant
Kubernetes
WaitSteponly reacts to pod updates, not deletions.DestroyWorkflowdeletes the service pod, so the detached goroutine remains blocked forever and never emits any final trace;Runthen waits on that goroutine until the overall timeout. This precisely reproduces the reported symptoms.A robust fix should make
WaitStepreact to deletion and return an exited state. I’ll inspect backend contracts and Kubernetes tests/helpers to implement this safely, including tombstone delete events and avoiding an unnecessaryGetafter deletion. I’ll also check whether the runtime should treat workflow-initiated service teardown as success versus external deletion as failure. - Assistant
I’ll replace the update-only wait logic with an informer lifecycle that:
- handles initial
Addevents (pod may already be terminal when waiting begins), - handles
Updateevents, - handles
Deleteevents, including Kubernetes tombstones, - waits for initial cache synchronization and treats a pod absent from that authoritative snapshot as already deleted,
- parses the terminal pod snapshot directly, avoiding a race-prone follow-up API
Get, - considers intentional deletion of detached/service steps a successful exit, while a deleted blocking step gets a non-zero exit.
This addresses both deletion after waiting starts and the reported race where log draining delays
WaitStepuntil after the pod has already disappeared. - handles initial
- Assistant
The source fix is in place. I’ll run the Kubernetes backend tests first (including race detection if practical), then the runtime and server pipeline status tests. Existing fake-client tests should validate informer cancellation/leak behavior; I’ll also create a temporary, untracked reproduction program/test outside the repository if existing tests do not cover pod deletion, since repository tests must not be changed.
- Assistant
The tests could not start because this sandbox has neither
GOMODCACHEnorGOPATHconfigured; this is an environment issue rather than a code failure. I’ll set both to temporary directories and rerun the same suites. - Assistant
Dependencies downloaded successfully, but Go additionally requires
GOCACHEbecause this minimal sandbox also has noHOME/XDG cache. I’ll provide a temporary build cache and rerun. - Assistant
All relevant existing tests pass, including the Kubernetes package under the race detector. To directly confirm the reported deletion path without altering repository tests, I’ll make a temporary copy outside the repository, add a one-off fake-Kubernetes test there, and exercise both races: deletion after
WaitStepbegins and deletion beforeWaitStepbegins. The temporary copy will not be submitted. - Assistant
The external reproduction now passes for both event orderings and returns
Exited=true, exit code 0 for the detached service. I’ll remove the temporary copy, run the broader pipeline/backend and agent test suites, rungo veton affected packages, and review the final diff/status for unintended files. - Assistant
The broader pipeline and agent suites pass.
go vetreported one pre-existing issue inpipeline/runtime/shutdown.go(discarded timeout cancel function), outside this change; Kubernetes vet itself still needs an isolated confirmation. I’ll run that, inspect the complete final diff once more, and then submit if clean.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.