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 analyze this issue:
- Woodpecker services (like postgres in the example) show as "running" even after the pipeline completes
- The pods are properly destroyed in Kubernetes, but the API still shows these services as running
- This seems to be a regression in 3.14.x releases
- The issue is likely in how the server handles service completion/stopping
Let me start by exploring the repository structure and understanding the codebase.
Assistant
Let me explore the structure more. The issue is about services not being marked as stopped. Let me look at the pipeline and server code
Assistant
Let me look at the pipeline directory since the issue is about pipeline services.
Assistant
Let me look at the pipeline backend and runtime directories, as they likely contain the code relevant to managing services.
Assistant
The issue mentions services and pipelines. Let me look at the runtime directory which probably handles the logic of running pipelines and services.
Assistant
Let me look at the runtime.go, step.go, and workflow.go files to understand how services are
Assistant
Let me look at workflow.go which is likely where the main execution logic is.
Assistant
Now let me look at step.go to understand how steps (including services) are executed.
Assistant
Let me look at the backend types to understand the step structure.
Assistant
Let me look at the backend types files.
Assistant
Let me look at the step types and backend interface
Assistant
Let me look at the backend interface
Assistant
Let me look at the pipeline state and how steps are traced.
Assistant
Let me look at the state directory.
Assistant
Let me look at state.go.
Assistant
Let me find the tracer implementation and how the state flows to the server.
Assistant
Let me look at the tracing directory
Assistant
Let me look at the tracer interface.
Assistant
Let me look at the agent's core agent.go which likely sets up the tracer.
Assistant
Let me find the Runner implementation that handles workflow execution.
Assistant
Let me look at the agent's runner.go and tracer.go.
Assistant
Let me look at the agent's tracer.go
Assistant
Let me check how
OnSuccessandOnFailureare set for steps, since theshouldSkipSteplogic depends on them.Assistant
Let me look at the compiler's convert.go to understand how OnSuccess and OnFailure are set.
Assistant
Let me look at the pipeline errors to understand the error types
Assistant
Let me look at the runtime errors
Assistant
Let me look at the kubernetes backend's implementation
Assistant
Let me look at the kubernetes backend's main file for WaitStep and DestroyWorkflow
Assistant
Let me look at the pod.go helper functions in the kubernetes backend
Assistant
Let me check the utils.go for helper functions
Assistant
Now I have a clear understanding of the issue. Let me trace the problem:
- Services are detached steps in the runtime
- When the stage loop completes,
destroyWorkflowFunc()is called beforeuploadWait.Wait() DestroyWorkflowdeletes the pods viastopPod- Meanwhile, the detached step goroutine is in
WaitStep, which uses an informer with onlyUpdateFuncregistered - When a pod is deleted,
DeleteFuncshould fire - but there's noDeleteFuncregistered - So
WaitStephangs until context timeout
The fix: register
DeleteFuncin bothWaitStepandTailStepto handle pod deletion events.Let me look at the
podUpdatedfunction signatures more carefully:Assistant
Let me open the file to see the exact lines
Assistant
Let me open the kubernetes.go file
Assistant
Now I have a clear understanding of the bug. Let me look at the imports in kubernetes.go to check what's available:
Assistant
Now let me check if
k8s.io/apimachinery/pkg/api/errorsis already imported in kubernetes.goAssistant
The
k8s.io/apimachinery/pkg/api/errorsis not imported inkubernetes.go. We need to add it. But wait, inpod.goit's imported as"k8s.io/apimachinery/pkg/api/errors"and used aserrors.IsNotFound(err). But inkubernetes.go, there's already a standarderrorsimport. So we'd have a naming conflict.Let me check how
pod.gohandles this:Assistant
Let me check how
errors.IsNotFoundis used in pod.goAssistant
Now I'll implement the fix. The changes needed:
- Add
DeleteFunchandlers inWaitStepandTailStepto close the channel when a pod is deleted - Handle the case where the pod was already deleted when trying to
Getit inWaitStep - Add the k8s errors import
Let me make the edits:
- Add
Assistant
Now I'll make the changes. First, let me add the k8s errors import and fix
WaitStep:Assistant
I see there's duplication. Let me fix the import block properly
Assistant
Good, let me re-read the file to confirm it's back to original
Assistant
Let me make the edits one at a time. First, add the kube_errors import:
Assistant
Good, import added. Now let me fix the
WaitStepfunction by adding DeleteFunc and handling deleted pods. Let me see the current lines:Assistant
Now let me fix WaitStep - replace the event handler registration and add podDeleted handler:
Assistant
Now I need to handle the "not found" case for the Get call after the select. Let me fix that:
Assistant
I see there's a stray
}on line 354. Let me fix this by looking at the full WaitStepAssistant
I see there's a stray
}and orphaned code. Let me fix the remaining part of WaitStepAssistant
Good. Now I need to fix the duplicate comment and add DeleteFunc to TailStep. Let me fix the duplicate comment first:
Assistant
Now let me fix TailStep to add DeleteFunc:
Assistant
Now let me verify the changes compile and are correct. Let me build the relevant package:
Assistant
Let me try to set up the Go environment
Assistant
Let me set up the full Go environment
Assistant
The code compiles successfully. Now let me think about edge cases and check the runtime logic once more.
Let me also look if there are any other backends that might have the same issue:
Assistant
Let me check where
uploadWait.Addis called in the runtime:Assistant
Let me also check the log streaming goroutines
Assistant
Let me verify the complete flow by looking at
DestroyStepandstopPodone more time to ensure idempotency:Assistant
Let me check the runtime tests for detached step behavior:
Assistant
Let me look at the relevant test for service steps
Assistant
Let me check the dummy backend to understand its WaitStep behavior
Assistant
Let me look at the dummy backend
Assistant
I realize I also need to handle the case where the pod was already deleted BEFORE
WaitStepcreates the informer. Let me add a pre-check inWaitStep:Assistant
There's duplication. Let me check what happened after line 355
Assistant
The file has too many duplications from my incremental edits. Let me reset and do a single clean edit of the entire
WaitStepandTailStepfunctions.Assistant
Let me reset the file and redo the changes cleanly:
Assistant
Now let me make the changes cleanly. First, add the import:
Assistant
Let me use a different approach - edit the file directly with sed-like commands:
Assistant
Let me verify the import was added correctly
Assistant
Now let me use a script to replace the entire
WaitStepfunction cleanly. Let me find the exact line numbers:Assistant
Let me create a script to replace the WaitStep function:
Assistant
Let me verify the changes:
Assistant
The code compiles. Let me verify the changes look correct:
Assistant
Let me verify TailStep:
Assistant
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
Let me run the tests properly:
Assistant
Let me check the test files more carefully:
Assistant
Let me check if there's a build constraint:
Assistant
Let me check the package name:
Assistant
Let me try running tests directly:
Assistant
Let me check for build tags:
Assistant
Let me check the build tags:
Assistant
Let me run the tests with the proper build tag:
Assistant
All tests pass. Let me see the final diff to make sure the changes are clean:
Assistant
The diff looks clean. Let me verify the code compiles one final time:
Assistant
The changes compile, pass vet, and all tests pass. Let me now submit.
Summary of Changes
Problem: Woodpecker services (detached steps) show as "running" even after pipeline completes. Root cause: The Kubernetes backend's
WaitStepandTailStepfunctions use Kubernetes informers to watch for pod state changes, but only registeredUpdateFunchandlers. WhenDestroyWorkflowdeletes a pod (viastopPod), the deletion event was not detected because noDeleteFuncwas registered. This causedWaitStepto hang indefinitely until the context timed out, keeping the step in "running" state.Fix (in
pipeline/backend/kubernetes/kubernetes.go):-
Added
DeleteFunchandler inWaitStep: Registers a handler that detects pod deletion and closes the channel, allowing to return.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.