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
I'll start by exploring the repository structure to understand the codebase and then locate where the service cleanup logic is handled.
Assistant
This is a Go-based project. Let me explore the repository structure more to understand the server component, which is mentioned in the issue.
Assistant
Let me explore the server directory structure, particularly looking for Kubernetes backend and pipeline-related code:
Assistant
Let me explore the server/pipeline directory since the issue is about pipeline services not being cleaned up properly.
Assistant
I see this is about the server-side pipeline management. Let me look at the files that handle pipeline status and step status since the issue is about services showing as "running" even after completion.
Let me also check if there's any Kubernetes backend code:
Assistant
Now I found the kubernetes backend. Let me explore it and understand how services are cleaned up. Let me also look at the step_status.go file since that's likely where the step states are being tracked.
Assistant
Let me read the key files to understand how services are managed. Let me start with the step_status.go file since the issue is about services showing as "running" in the API/UI even after they're destroyed.
Assistant
Let me try using the bash command to read the file.
Assistant
Let me read the workflow_status.go file to understand how pipeline/workflow completion is handled:
Assistant
Now I'm starting to understand. Let me look at the pipeline_status.go file to see how the pipeline itself is updated, and also look at the kubernetes backend to see how it handles service cleanup.
Assistant
Now let me look at the kubernetes backend to understand how services are cleaned up and when the pipeline completion is communicated back.
Assistant
Now let me look at the pipeline engine to understand how services are managed during pipeline execution. The key is to understand how services and steps interact:
Assistant
Now let me look at the workflow execution to understand how services are managed. Let me check the runtime workflow and step files:
Assistant
Now let me look at the step.go file to understand how steps are executed:
Assistant
Assistant
Let me follow the proper format for tool calls.
Assistant
OK, now I see that the Docker backend's
DestroyWorkflowuses anerrgroupto parallelize the cleanup. The Kubernetes backend'sDestroyWorkflowiterates sequentially. But that's a minor difference.Let me now focus on the actual issue. Looking at the issue again, the problem is that the server's API still shows services as "running" even after they've been destroyed. This suggests the issue is on the server side, not the agent side.
Actually, wait. Let me re-read the issue: "the woodpecker API still shows these steps as state=running"
The API on the server shows steps. The server receives step state updates via RPC from the agent. So the issue is that the agent doesn't report the step completion for services.
Let me look at the agent code to see how it runs the workflow:
<tool_call> <function=bash_terminal> <parameter=command> cat /woodpecker/agent/runner.go </parameter> </function> </tool_call>Assistant
Let me follow the proper format with the tool call.
Assistant
Assistant
Let me use the proper format to call the bash command.
Assistant
Now I have a good understanding of the issue. Let me trace through what happens:
- Service pods (detached steps) are started and their background goroutines call
WaitStepto wait for pod completion - Command steps (blocking) run and complete
- When the stage completes,
DestroyWorkflowis called which deletes all pods including services - The service pods'
WaitStepis blocked waiting for the informer to signal completion - The bug: The informer only has
UpdateFuncset, but when a pod is deleted, the Kubernetes informer triggers a DELETE event. Without aDeleteFunchandler, this event is ignored, and thefinishedchannel is never closed
Let me verify this by examining the informer setup more closely:
- Service pods (detached steps) are started and their background goroutines call
Assistant
Now I understand the bug. The informer in
WaitSteponly handlesUpdateFuncbut notDeleteFunc. When a pod is deleted byDestroyWorkflow, the informer receives a DELETE event, but since there's noDeleteFunchandler, the event is ignored and thefinishedchannel is never closed. This causesWaitStepto block forever.Let me look at the complete WaitStep function to understand the fix:
Assistant
Now I fully understand the bug. The
WaitStepfunction in the Kubernetes backend sets up an informer that only handlesUpdateFunc. When a pod is deleted byDestroyWorkflow, the informer receives a DELETE event, but since there's noDeleteFunchandler, the event is ignored and thefinishedchannel is never closed. This causesWaitStepto block forever, and the service step state is never updated.Let me create a test script first to verify my understanding:
Assistant
Now let me check the existing tests to understand how this is tested:
Assistant
Now I understand the issue. Let me trace through the root cause:
Root Cause: In the Kubernetes backend's
WaitStepfunction, the informer only hasUpdateFuncset (notDeleteFunc). WhenDestroyWorkflowis called after the pipeline completes, it deletes the service pods. When a pod is deleted, the Kubernetes informer triggers a DELETE event, but since there's noDeleteFunchandler, this event is silently ignored. Thefinishedchannel is never closed, causingWaitStepto block indefinitely. This prevents the service step state from being updated on the server.The Fix: Add a
DeleteFunchandler to the informer's event handlers that closes thefinishedchannel when the deleted pod matches the expected pod.Let me implement this fix:
Assistant
Let me look at the complete WaitStep function to understand where I need to make the change:
Assistant
Now I understand the issue clearly. Let me analyze the root cause:
Root Cause Analysis:
In the
WaitStepfunction of the Kubernetes backend, the informer only has anUpdateFunchandler set up. WhenDestroyWorkflowis called after the pipeline completes, it deletes all service pods. When a pod is deleted:- The Kubernetes informer receives a DELETE event
- Since there's no
DeleteFunchandler, this event is silently ignored - The
finishedchannel is never closed WaitStepblocks indefinitely waiting for the channel to close- The service step state is never updated on the server
The fix is to add a
DeleteFunchandler to the informer's event handlers that closes thefinishedchannel when the deleted pod matches the expected pod name.Let me implement this fix:
Assistant
Now I need to understand the code better. There are two places where the informer is used:
- In
WaitStep(line 315) - In
TailStep(line 394)
For
WaitStep, we need to handle pod deletion becauseDestroyWorkflowdeletes the pods. ForTailStep, we might also want to handle deletion, but let me focus onWaitStepfirst.The fix is to add a
DeleteFunchandler to the informer's event handlers inWaitStep. Let me read the exact lines around line 315 to understand the structure better.- In
Assistant
Now I understand the issue clearly. The
WaitStepfunction only handlesUpdateFuncfor the informer. When pods are deleted byDestroyWorkflow, the DELETE event is ignored because there's noDeleteFunchandler, causingWaitStepto block forever.Let me implement the fix by adding a
DeleteFunchandler:Assistant
Let me try the edit command with proper formatting. I need to use the
editcommand with the--fileoption.Assistant
I need to fix the edit command format. Let me try using the create command to view the exact format needed, or just use the edit command correctly.
Looking at the error messages, it seems like the tool is not parsing my commands correctly. Let me try a different approach - I'll use sed or a different method to make the edit.
Actually, let me re-read the error. The issue is that I'm not formatting the tool call correctly. The tool call should be in JSON format with the correct keys.
Looking at the system prompt, the edit command should be:
edit 1:1 "Your Replacement Text Here"or with file option:
edit --file path/to/file 1:1 "Your Replacement Text Here"For multi-line text, I need to use:
edit 1:1 << 'EOF' Line1 Line2 EOFLet me try this approach.
Assistant
Now I can see the exact lines. I need to add a
podDeletedfunction and include it in theResourceEventHandlerFuncs. Let me use the edit command with proper heredoc syntax:Assistant
I see the issue - the tool calls aren't being parsed correctly. Let me try using a different approach with the bash terminal to make the edit.
Assistant
I see the issue with my tool call format. Let me use bash commands to make the edit directly:
Assistant
Let me try a different approach using a Python script to make the edit:
Assistant
Let me verify the changes were applied correctly:
Assistant
The edit didn't work correctly. Let me restore the file and try a cleaner approach.
Assistant
Let me try a cleaner Python script approach:
Assistant
Let me verify the changes look correct:
Assistant
The changes look correct. Now let me verify the code compiles:
Assistant
The go build command failed because the module cache is not set up. Let me try with different environment variables.
Assistant
Let me try setting environment variables and building:
Assistant
The code compiles successfully. Now let me run the existing tests to make sure my change doesn't break anything:
Assistant
Good, the tests are passing! Let me see the complete test output:
Assistant
All tests pass. Now let me create a test to verify that my fix works correctly for the specific scenario described in the issue. Let me first look at the existing kubernetes_test.go file to understand how tests are structured:
Assistant
Let me look at the existing test to understand the test structure:
Assistant
Let me look at the helper functions used in the tests:
Assistant
Let me think about edge cases. When the pod is deleted by
DestroyWorkflow, theWaitStepfunction will return after thefinishedchannel is closed. But then the code tries toGetthe pod, which will fail because the pod has been deleted.Let me check what happens after the
finishedchannel is closed:Assistant
Assistant
I need to use the proper format for bash commands.
Assistant
Now let me also add the
DeleteFunchandler toTailStepfor consistency and to prevent similar issues:Assistant
Let me verify the changes to TailStep were applied correctly:
Assistant
Both changes look correct. Let me verify the code compiles and the tests pass:
Assistant
Good, the code compiles. Let me run the tests to make sure they still pass.
Assistant
All tests pass. Let me verify my changes by looking at the git diff:
Assistant
The changes look correct. Let me run the full test suite for the pipeline package to ensure everything works properly:
Assistant
Let me check what test failed:
Assistant
Let me check what's wrong with the dummy backend build.
Assistant
The dummy backend has build constraints that exclude it, which is unrelated to my changes. Let me verify my changes didn't introduce any new issues by running just the kubernetes backend tests again:
Assistant
All tests pass. Let me also run the server pipeline tests to ensure the fix works end-to-end:
Assistant
All tests pass. Let me verify the final state of my changes:
Assistant
Let me verify the final changes and ensure they're complete:
Assistant
Now let me provide a summary of the fix and submit it:
Summary
Root Cause: In the Kubernetes backend's
WaitStepandTailStepfunctions, the informer only had anUpdateFunchandler set up. WhenDestroyWorkflowis called after the pipeline completes, it deletes all service pods. However, when a pod is deleted, the Kubernetes informer receives a DELETE event. Since there's noDeleteFunchandler, this event is silently ignored, thefinishedchannel is never closed, andWaitStepblocks indefinitely. This prevents the service step state from being updated on the server, causing the API/UI to show the service as "running" even though the pod is gone.Fix: Added a
DeleteFunchandler to the informer's event handlers in bothWaitStepandTailStepfunctions. This handler:Assistant
I need to call submit with the proper format. Let me try the correct format.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.