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 investigate how Woodpecker handles service lifecycle and cleanup after pipeline completion, focusing on the Kubernetes backend.
- Assistant
I'll search the codebase for how services are stopped and their state is updated after pipeline steps finish.
- Assistant
rg is not available, let me use grep instead.
- Assistant
I'll inspect the runtime layer and Kubernetes backend for how service steps are started, waited on, and marked complete.
- Assistant
The Kubernetes side may destroy pods correctly while the agent never reports service steps as finished—I'll check the workflow runner next.
- Assistant
Let me look at the step execution - specifically how services/detached steps are handled.
- Assistant
Let me read the rest of step.go for runDetachedStep
- Assistant
Let me continue reading for runDetachedStep
- Assistant
I'll examine Kubernetes WaitStep/Destroy and recent regressions that may leave service steps stuck in "running".
- Assistant
There are prior commits about services hanging and stuck running state—I'll inspect those next.
- Assistant
So PR #6507 intentionally tears down workflow after stages so services can finish. The issue is that with kubernetes, when DestroyWorkflow is called, WaitStep might not notice the pod was deleted.
- Assistant
Confirmed: DestroyWorkflow deletes pods, but WaitStep only listens for status updates—not deletions. Checking the dummy backend and WaitStep return path next.
- Assistant
Root cause: WaitStep only watches Update events, so deleted service pods never finish. Checking tests and how a deleted pod should be reported.
- Assistant
Race confirmed:
WaitStepcan start after the pod is already gone. I'll inspect the full WaitStep implementation and related helpers before applying a fix. - Assistant
Looking at pod.go for how they import errors:
- Assistant
Implementing WaitStep to handle deleted pods and the race where the pod is already gone when waiting starts.
- Assistant
I'll update the imports and rewrite
WaitStepto handle pod deletion correctly. - Assistant
Next I'll replace the WaitStep function body.
- Assistant
I'll verify the rest of WaitStep and run the existing Kubernetes backend tests.
- Assistant
I'll write a temporary test covering pod deletion and the already-deleted race, then run the package tests.
- Assistant
Need to set GOPATH/GOMODCACHE
- Assistant
Tests passed. Removing the temporary test file, then running the full package suite.
- Assistant
Interesting — pipeline/runtime reported no test files; checking whether build tags are involved.
- Assistant
Need -tags test
- Assistant
Checking whether TailStep can hang if the pod is deleted while detachd services are still starting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.