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
Now let's view the exact WaitStep function with line numbers for precise editing.
Assistant
Now let's implement the fix with a DeleteFunc handler.
Assistant
Build succeeds. Now let's run the kubernetes backend tests and the runtime tests.
Assistant
Good. Now let's write a quick reproduction test to simulate a service pod being deleted mid-wait (mimicking DestroyWorkflow behavior) to confirm the fix works as intended.
Assistant
The fix works as intended. Now let's remove the temp test file and run the full test suite for kubernetes backend and pipeline/runtime.
Assistant
All tests pass. Now let's run the full pipeline/runtime test suite too, and other related backend tests.
Assistant
Ah, it needs the
testbuild tag.Assistant
All tests pass, including
pipeline/runtime(withTestWorkflowUnboundedServiceDoesNotHang) andpipeline/backend/kubernetes.Let's also check
serverpackage tests since they touch step_status logic to be safe.Assistant
Let's view the final diff to double check everything is clean.
Assistant
No formatting issues. Now let's write a broader reproduction test simulating the full runtime scenario with kubernetes-like semantics (pod deletion happening via DestroyWorkflow while WaitStep is blocked) to be thorough, then clean up.
Assistant
Confirmed working end-to-end. Now clean up the temp test file.
Assistant
Let's do a final full test run to make sure nothing regressed.
Assistant
Confirmed pre-existing and unrelated to my change. Let's view the final diff once more before submitting.
Assistant
This looks clean and complete. Let's go through the checklist.
Assistant
All tests pass, including
TestWorkflowUnboundedServiceDoesNotHang.Now let me review the checklist:
Assistant
Let's rigorously confirm the bug existed before the fix by testing against the original code.
Assistant
Confirmed: the bug is reproducible on the original code (WaitStep hangs after pod deletion). Now let's restore the fix and remove the temp test.
Assistant
Fix restored and confirmed working. Let's run the full test suite one final time to be safe.
Assistant
All good. Let me summarize the checklist and final review.
Checklist review:
-
Reproduced the error: Yes. I traced the root cause: the Kubernetes backend's
WaitSteponly detects completion via pod phase transitions (//) observed through an informer handler, or via context cancellation. When the workflow finishes normally, the runtime's / directly the service's pod (since it's still running as a detached step) without ever transitioning it through a terminal phase, and the workflow's context isn't canceled at that point (it's only canceled after returns, or on the pipeline timeout). This leaves blocked forever — until the outer pipeline timeout eventually fires — exactly matching the reported symptom ("only cleaned after the pipeline times out"). I wrote a temporary test that reproduced this hang against the original code and confirmed it hangs.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.