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
codeservices: - 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.
codepr-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.
- Assistant
I'll start by exploring the repository structure and understanding how pipeline services are cleaned up after completion.
- Assistant
Let me search for how services are stopped and their state is updated when a pipeline finishes.
- Assistant
rg is not found, let me use grep instead.
- Assistant
I'll inspect the pipeline runtime and how step/service state is updated on completion.
- Assistant
There's a test specifically about unbounded services — I'll read the runtime step and workflow code next.
- Assistant
Let me continue reading the rest of the file, especially the detached step handling.
- Assistant
Continue reading for runDetachedStep
- Assistant
Looking at the issue more carefully - the pods are destroyed properly, but the API still shows services as running. So the destroy happens but the state isn't updated to stopped in the server/API.
- Assistant
I see Redo: destroy provides first, then waits for traces — I'll check the Kubernetes backend and the hanging-service test.
- Assistant
I'll inspect how kubernetes and Kubernetes backends handle DestroyWorkflow and WaitStep for services.
- Assistant
Let me look at how WaitStep works for k8s and when DestroyWorkflow is calledings - the order of destroy might cause WaitStep context cancellation before the state is properly traced.
- Assistant
I see a potential race condition:
- Assistant
Confirming the Kubernetes WaitStep may miss pod deletions — I'll inspect DestroyWorkflow and pod lifecycle handling.
- Assistant
I think I've found the bug: logs end when the pod is destroyed, then WaitStep starts watching a pod that no longer exists. Let me verify TailStep behavior and recent related changes.
- Assistant
There are related commits — I'll inspect the service hang fix and the stuck-running-state handling.
- Assistant
Let me check how the Docker backend handles WaitStep vs destroy, and review the hang-fix commit.
- Assistant
Let me look at docker WaitStep to understand the contract - DestroyWorkflow kills containers which makes Wait return.
- Assistant
The Kubernetes WaitStep doesn't handle pods already deleted by DestroyWorkflow — I'll inspect tests and the backend contract next.
- Assistant
Let me read more of the WaitStep for k8s and the rest of the file for how state is built. Also look at recent git history of WaitStep.
- Assistant
Let me examine how step state tracing and workflow completion work on the server side.
- Assistant
There's server-side logic that should finish stuck services — I'll inspect that next.
- Assistant
The agent never reports Done because WaitStep hangs for services. Let me check how the agent reports workflow completion.
- Assistant
Let me read agent/runner.go around the Run method to understand the flow.
- Assistant
Let me check docker Destroy again and whether docker also has similar races.
- Assistant
The ordering of waitForLogs before WaitStep looks wrong for services. I'll check the local backend to confirm.
- Assistant
Let me look at local WaitStep and TailStep and also check git blame쑝 on completeStep waitForLogs.
- Assistant
I'll check the history of completeStep's waitForLogs/WaitStep ordering to see what the intended contract is.
- Assistant
I'll inspect existing Kubernetes WaitStep tests and helpers next.
- Assistant
Let me inspect stopPod and related utilities.
- Assistant
I'll check kubernetes.go imports and whether container statuses can be read after pod termination.
- Assistant
I'll check how the server finalizes stuck service steps.
- Assistant
Checking how StopTimeout and delete options interact for running pods.
- Assistant
I have a clear picture: Kubernetes WaitStep misses deleted pods, and completeStep waits for logs before WaitStep so Wait may start after destroy. Implementing both fixes.
- Assistant
Let me implement the WaitStep fix and the completeStep order fix.
- Assistant
Now replacing the WaitStep function with a version that handles deleted pods.
- Assistant
Next I'll fix completeStep so WaitStep runs before draining logs.
- Assistant
Looking at incomplete waitState nil case - if Wait succeeds but waitState is somehow nil... unlikely.
- Assistant
I'll add unit tests for WaitStep when pods are already deleted or deleted while waiting.
- Assistant
I'll append tests at the end of the file.
- Assistant
Let me append tests after line 304.
- Assistant
I need to fix a typo in the test —
UpdateStatusbaseis wrong. - Assistant
Need to goto that line first or use --file
- Assistant
Let me fix the typo now that the file is open.
- Assistant
I shouldn't have added tests to the repository — removing them and using a temporary script instead.
- Assistant
I'll run the existing runtime and Kubernetes package tests to verify the fix.
- Assistant
Need to set GOPATH or GOMODCACHE
- Assistant
Runtime reported no test files — checking for build tags.
- Assistant
Need -tags test
- Assistant
I'll write a temporary script to verify WaitStep handles deleted pods, run it, then remove it.
- Assistant
Verifying dummy TailStep still works with the new Wait-then-drain order:
- Assistant
Confirming deleted-pod success exits become non-running traces. Running a broader compile/test check:
- Assistant
All tests passed. I'll do a final review of the diff.
- Assistant
Restoring an error when a present finished pod has no container statuses — only NotFound should soft-succeed.
- Assistant
When Terminater is nil due only to race where DeleteFunc firesd but pod still briefly exists without terminated... span isPodFinished might not be true from Update, only Delete fires, then Get NotFoun...
- Assistant
Fixing a race where a deleted/terminating pod isn't treated as finished after the Delete event.
- Assistant
Need to navigate to the right place.
- Assistant
I'll fix both isPodFinished and the return after select and podToState for deletion without terminated.
- Assistant
Re-running the tests after the race fix:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.