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
The issue is about Woodpecker services not being properly cleaned up on the API/UI side when using Kubernetes backend. The pods are destroyed but the API still shows the service steps as "running", which prevents pipelines from completing (they stay in running state until timeout).
Let me start by exploring the repository structure to understand the codebase.
This is a Go project (Woodpecker CI). Let me look at the structure.
Assistant
Let me explore the relevant directories for the pipeline execution and Kubernetes backend
Assistant
Let me run one command at a time.
Assistant
This is the Woodpecker CI repository. Let me explore the backend directory to find the Kubernetes backend implementation.
Assistant
Let me look at the Kubernetes backend and the pipeline runtime.
Assistant
Let me examine the Kubernetes backend files to understand how services are handled
Assistant
Let me now look at the pipeline runtime and the backend types to understand the
Assistant
Let me look at the runtime and step files:
Assistant
Let me look at the step.go file
Assistant
Let me look at the workflow.go file
Assistant
Let me understand the flow better. Let me look at the backend types to understand step types.
Assistant
Let me look at the stopPod function in pod
Assistant
Let me look at the git history for recent changes to the runtime and the overall flow:
Assistant
Very interesting! Let me look at commit
60df1c618- "Fix workflow hang on services":Assistant
Let me see the actual diff of that commit:
Assistant
Let me look at the dummy backend to see how it handles
DestroyWorkflow:Assistant
Now I understand the issue. Let me look at the Docker backend to compare:
Assistant
Let me look at the Docker backend's WaitStep and DestroyWorkflow implementation
Assistant
Let me now look at the runtime tests to understand the expected behavior for services:
Assistant
Let me look at the test for workflows with service steps
Assistant
Let me now look at the tests for unbounded services and how they're handled
Assistant
Let me search for tests using unbounded services:
Assistant
Let me see the tests using unbounded services
Assistant
Now I have a clear understanding of the issue. Let me look at the local backend too:
Assistant
Let me look at the local backend's key functions
Assistant
Now I understand the issue fully. Let me verify the current code before making changes
Assistant
Let me see the full WaitStep and TailStep functions
Assistant
Let me see the full TailStep:
Assistant
Now I understand the issue. The Kubernetes backend's
WaitStepandTailSteponly handleUpdateFuncin their informers. WhenDestroyWorkflowdeletes pods, theWaitStepgoroutine never detects the deletion and hangs until the context times out.The fix is to add
DeleteFunchandlers to bothWaitStepandTailStepinformers, and handle 404 errors gracefully when the pod has already been deleted.Let me implement the fix.
Assistant
Let me open the file:
Assistant
Now let me make the edits. First, I'll fix
WaitStepby adding aDeleteFunchandler:Assistant
Let me use the proper edit syntax with heredoc:
Assistant
Let me try a different approach with the edit command:
Assistant
Let me check the area around the edit to make sure the braces are correct:
Assistant
I see there's a missing closing brace. The
if pod.Name == podNameblock was not properly closed. Let me fix this:Assistant
Let me use the correct syntax:
Assistant
There are duplicate lines. Let me remove the duplicate
podDeletedfunction:Assistant
I need to remove the duplicate
siblock. Let me fix that:Assistant
Good. Now let me handle the 404 case in
WaitStep's Get call. But first let me check the imports in kubernetes.go:Assistant
Let me check how
IsNotFoundis used in the codebase:Assistant
Let me check pod.go's imports:
Assistant
Now I need to:
- Add the k8s errors import
- Handle 404 in WaitStep
- Add DeleteFunc to TailStep
Let me first add the import:
Assistant
There's a duplicate line. Let me fix it
Assistant
Now let me handle the 404 in WaitStep's Get call. Let me see the current state:
Assistant
Now let me handle the 404 case
Assistant
I accidentally removed the
pod, err := ... Get(...)line. Let me fix thatAssistant
Good,
WaitStepis fixed. Now let me updateTailStepsimilarly. Let me see the full TailStep function:Assistant
Now let me add
DeleteFunctoTailStepas well:Assistant
Now let me verify the changes compile correctly:
Assistant
Let me check Go setup:
Assistant
Let me set GOPATH and try again:
Assistant
Let me set the required Go environment variables:
Assistant
The code compiles. Now let me run the Kubernetes backend tests:
Assistant
Let me run all Kubernetes backend tests:
Assistant
All Kubernetes backend tests pass. Let me also run the runtime tests:
Assistant
The runtime tests might have a build tag. Let me check:
Assistant
Let me run the unbounded service tests:
Assistant
All tests pass. Let me do a final review of my changes:
Assistant
The diff looks clean and correct. Let me run the full test suite for the affected packages:
Assistant
All tests pass. Let me also check the common backend to see if there's anything there:
Assistant
Let me verify the build one final time:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.