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
Let me start by understanding the repository structure and the issue. The issue is about Woodpecker CI services not being properly cleaned up when using the Kubernetes backend. The pods are destroyed but the API still shows services as "running" state, which prevents pipelines from completing.
Let me explore the repository structure first.
Assistant
Let me explore the relevant parts of the codebase. The issue is about services not being properly cleaned up after pipeline steps complete. Let me look at the pipeline execution and Kubernetes backend code
Assistant
Let me look at the pipeline package which likely contains the core pipeline execution logic
Assistant
Let me look at the pipeline runtime and backend directories, as these are likely where the service lifecycle management happens.
Assistant
I need to make only one tool call at a time. Let me look at the runtime directory first.
Assistant
Let me look at the key files. The shutdown.go and runtime.go are probably the most relevant.
Assistant
Let me look at runtime.go and step.go
Assistant
Let me look at the workflow.go file which likely controls the execution flow.
Assistant
Now let me look at step.go to understand how steps and services are executed:
Assistant
Let me look at the Kubernetes backend implementation:
Assistant
Let me look at the main Kubernetes backend implementation
Assistant
Let me look at the git log for recent changes related to services, detached steps, and the workflow runtime:
Assistant
Let me search for commits that may have changed the runtime or service handling recently
Assistant
Let me look at the commit that tried to fix workflow hang on services
Assistant
Let me see the full diff of this commit
Assistant
Now let me look at the pod.go file to understand how pods are stopped
Assistant
Now I understand the issue. Let me look at the
utils.gofile for any helper functionsAssistant
Let me check the service.go file
Assistant
Now I have a clear understanding of the issue. Let me look at the kubernetes tests to understand the test structure
Assistant
Let me check the backend interface to understand the contract:
Assistant
Let me look at the backend types interface
Assistant
Let me list the directory.
Assistant
Now I have a thorough understanding of the issue. Let me create a reproduction script and then fix it.
The issue is in
WaitStepinkubernetes.go: whenDestroyWorkflowdeletes a pod, the informer inWaitStepdoesn't detect this because:- Only
UpdateFuncis registered (noDeleteFunc) - The
UpdateFunconly reacts to terminal pod phases (Succeeded, Failed, Unknown), but a deleted pod doesn't transition to a terminal phase
Let me first create a small script to verify the issue, then implement the fix.
- Only
Assistant
Let me check the Go environment
Assistant
Let me set up the Go module cache
Assistant
Let me try building the project.
Assistant
Let me set up all Go environment variables
Assistant
Let me run the Kubernetes backend tests to make sure they pass currently
Assistant
Now let me implement the fix. The issue is in
WaitStepandTailStepinkubernetes.go. I need to add aDeleteFunchandler and check forDeletionTimestampin theUpdateFunc.Let me open the kubernetes.go file to edit it
Assistant
Let me open the file
Assistant
Let me see more of the WaitStep function
Assistant
Let me see the rest of TailStep
Assistant
Now I understand the issue fully. Let me implement the fix. I'll modify both
WaitStepandTailStepto handle pod deletion.First, let me fix `WaitStep
Assistant
Good. Now I need to also handle the case where the pod
Getreturns "not found" after deletion - we should return a clean state rather than an error. Let me update that part:Assistant
Let me check the imports to make sure
errorsfrom k8s API is already importedAssistant
Let me see the full imports of kubernetes.go
Assistant
Let me check how pod.go imports the k8s errors package
Assistant
Let me try to compile to check for errors
Assistant
Let me check the full imports of pod.go more
Assistant
Let me check how
errors.IsNotFoundis used in the codeAssistant
Let me revert my changes and check if the original code compiles
Assistant
Let me revert and test the original code compilation
Assistant
Let me check the original imports once more
Assistant
Let me check how
errorsis used in kubernetes.goAssistant
I see - each Go file has its own import scope. In
kubernetes.go,errorsis the stdlib. I need to import the k8s API errors with an alias. Let me restore my changes and fix thisAssistant
Now I need to add the k8s API errors import with an alias. Let me fix the imports first
Assistant
The edit has duplicated the imports. Let me fix this by reverting and redoing the edit more
Assistant
Good. Let me now make the changes more carefully, step by step. First, add the k8s API errors import:
Assistant
I have duplicates. Let me revert and try a cleaner approach
Assistant
Let me use
replaceto insert the importAssistant
Good, import added. Now let me modify
WaitStep. First, add theDeletionTimestampcheck after the ImagePullBackOff check:Assistant
Let me navigate to line 302.
Assistant
Now let me add the DeletionTimestamp check
Assistant
I see duplicates. Let me fix them
Assistant
Let me fix the duplicate closing braces
Assistant
Good, WaitStep podUpdated looks correct now. Let me add the
DeleteFunchandlerAssistant
I see a syntax issue. The
); err != nil {part was lost. Let me fixAssistant
Good. Now let me handle the "not found" error after
Getin WaitStepAssistant
Now let me fix
TailStepsimilarly - addDeletionTimestampcheck andDeleteFuncAssistant
Let me check if there's a missing closing brace in TailStep's podUpdated
Assistant
Let me view around line 415-425 to understand the structure
Assistant
I see a missing closing brace for the
podUpdatedfunction. Let me fix itAssistant
Now let me add the
DeleteFunchandler for TailStepAssistant
Now let me compile to check for errors
Assistant
The code compiles. Now let me run the tests
Assistant
All Kubernetes backend tests pass. Let me also run the pipeline runtime tests
Assistant
Let me check the correct test path
Assistant
Let me run from the correct
Assistant
Let me check for build tags in the test files
Assistant
Let me check the package declaration in the test file
Assistant
The tests have a build tag
test. Let me run with the tagAssistant
All tests pass. Let me also specifically check the unbounded service tests
Assistant
All tests pass. Let me review the final diff of my changes
Assistant
The diff looks correct. Let me do a final full build to make sure everything
Assistant
The web package build error is unrelated to our changes (missing web UI build artifacts). Let me verify the relevant packages build correctly
Assistant
Let me just build the pipeline packages
Assistant
Let me run all kubernetes tests one final time to
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.