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.
- Checked that the bug isn't fixed in the
nextversion already [https://woodpecker-ci.org/versions]
Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /woodpecker, current file: none) bash-$
Assistant
Good, there's a consistent pattern. Let's view the exact WaitStep code with line numbers to edit precisely.
Assistant
Good, uses fake clientset. Let's view the WaitStep tests fully to understand pattern for writing a similar test (though I won't add new tests, per instructions, but I can use fake client for a repro script).
Assistant
Need to add the errors import for IsNotFound. Let's view the import block.
Assistant
Now let's edit line 34-35 to add the import.
Assistant
Now let's update WaitStep function (now shifted by +1 line, so line 283-359 originally becomes 284-360).
Assistant
Now let's find the WaitStep function's new line numbers and update the body.
Assistant
Now replace lines 292-336 with the new logic including DeleteFunc handling and NotFound handling.
Assistant
Now let's view the rest to make sure the NotFound handling block after is correct and not duplicated.
Assistant
Good, that looks clean. Now let's build the package to verify compilation.
Assistant
Compiles successfully. Now let's run the existing kubernetes backend tests.
Assistant
Now let's write a temporary reproduce/test script using the fake clientset to simulate a service pod deletion (without going through terminal phase) and confirm WaitStep returns instead of hanging.
Assistant
Now let's write a temp test file to reproduce the hang scenario (pod deleted while still Running phase, no terminal phase transition), to prove the fix works.
Assistant
The fix works. Let's confirm the old code would hang (revert temporarily) to prove this was indeed the bug, then restore.
Assistant
Now let's run the full test again with fix restored, then remove the temp repro test file (since instructions say not to add new tests to the repo).
Assistant
Now let's remove the temp test file and run the full existing test suite for the kubernetes package plus runtime package to make sure nothing broke.
Assistant
All tests pass. Let's also check TestWaitStepReturnsOnContextCancel and TestWaitStepNoGoroutineLeak specifically since they touch the same function.
Assistant
Now let's run the whole pipeline test suite (runtime, backend) to make sure nothing else broken.
Assistant
That's unrelated (missing frontend build artifacts). Let's run tests for pipeline packages specifically.
Assistant
They require the
testbuild tag. Let's rerun with that tag.Assistant
All tests pass. Now let's double check the runtime.go's
TestWorkflowUnboundedServiceDoesNotHangtest (which tests the dummy backend teardown scenario, already fixed by prior commit) still passes, confirming both fixes complement each other.Assistant
Good. Now let's review the final diff.
Assistant
Clean. Let's also check if
gofumptis available (the repo mentioned gofumpt formatting in earlier commit) to be consistent with style.Assistant
Good, that's already tolerant. This confirms our fix integrates well:
DestroyWorkflowdeletes pod → ourDeleteFunchandler fires →WaitStepreturns a synthetic completed state →completeStepproceeds to callDestroyStep(idempotent, tolerant of already-deleted pod) →traceStepreports the step as finished. Let's verifyDestroyStep'sstopPodcall also tolerates already-deleted secrets etc.Assistant
Good,
stopPodis NotFound-tolerant, andstopRegistrySecret/stopStepSecretlikely are too (per earlier grep). This confirms the fix integrates cleanly with the rest of the teardown flow. Let's view the whole final function once more for a sanity check.Assistant
This looks solid. Let's run the complete relevant test suite once more and also check golangci-lint config briefly for the changed file if available.
Assistant
All good. Let's clean up and check final git status/diff.
Assistant
Only the intended file is modified. No leftover temp test files.
Assistant
Good, the temp repro test file was removed successfully (grep found nothing, exit code 1 confirms no match).
Checklist Review
1. If an error was reported in the issue description, I have successfully reproduced it.
Assistant
I confirmed this: I traced the root cause to
pipeline/backend/kubernetes/kubernetes.go'sWaitStep, which watches pod Update events for a terminalPhase(Succeeded/Failed/Unknown). Kubernetes does not transitionPod.Status.Phaseto a terminal value when a still-running pod is simply deleted (as happens for service pods torn down byDestroyStep/DestroyWorkflowat the end of a normal workflow) — the pod object is just removed. Since only anUpdateFunchandler was registered (noDeleteFunc), thefinishedchannel never closed, soWaitStepblocked forever,completeStepnever returned, and the step was never traced as finished — exactly matching the reported symptom ("Stopped: 0", "State: running" forever, until the pipeline's own timeout eventually force-resolves it). I wrote a temporary test using the fake Kubernetes client to simulate this exact sequence (create pod inRunningphase → delete it while still running) and confirmed viagit stash/git stash popthat this hung on the original code and passes with my fix.2. If an error was reported in the issue description, I have confirmed that my fix resolves the error.
Assistant
3. I have thought about edge cases and made sure my fix handles them as well.
Assistant
4. I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
Assistant
All tests in the affected
pipelinemodule (includingpipeline/backend/kubernetesandpipeline/runtime) pass with thetestbuild tag required by this repo's test files.go vetandgofmt -lalso reported no issues for the modified file.The fix is complete, minimal, and targeted: it adds a
DeleteFunchandler to the Kubernetes informer used inWaitStep(to catch pods removed before they ever reach a terminalPhase, which is exactly what happens to service pods torn down byDestroyStep/DestroyWorkflowat the end of a workflow) and gracefully handles aNotFoundresponse from the subsequentGetcall. This ensuresWaitStepalways returns promptly instead of hanging forever, allowing the runtime to trace the step as finished so the API/UI no longer shows services as perpetually "running".
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →