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
Let me start by understanding the repository structure and the issue. The issue is about Woodpecker services not being properly cleaned up on the API side when using Kubernetes backend. The pods are destroyed but the API still shows the service as "running". This seems like a regression in the 3.14.x releases.
Let me explore the repository structure first.
Assistant
This is a Go project. The issue is about services not being properly cleaned up - specifically, the service steps show "running" state even after the pods are destroyed. Let me explore the relevant parts of the codebase.
The issue mentions:
- Kubernetes backend
- Services in pipelines
- The service steps show state=running even after pods are destroyed
Let me look at the pipeline and server directories, especially around service handling and Kubernetes backend.
Assistant
Let me look at the pipeline execution and backend code more
Assistant
Let's explore the kubernetes backend and also look at how services are handled in the pipeline.
Assistant
Let's look at the kubernetes.go file - this is the main backend implementation. Also let's look at how services are handled during pipeline execution.
Assistant
Now let me look at how the pipeline runner handles steps, especially services:
Assistant
Let me look at the main pipeline runner. I think there's a
pipeline.goorrunnerfile somewhere.Assistant
Let me look at the runtime, which is likely where step execution happens
Assistant
Let me look at the runtime.go and step.go files.
Assistant
Let me look at the files one by one.
Assistant
This isn't the main logic. Let me look at step.go and workflow.go.
Assistant
Now let me look at the
Assistant
Let me look at the backend types to understand the step types.
Assistant
Let me look at the compiler to understand how services are compiled into steps, especially the Detached field
Assistant
Let me check the
convert.goto see how services are convertedAssistant
Let me look at the shutdown.go and understand the context lifecycle
Assistant
Let me look at the agent to understand how it runs pipelines and sends step status updates
Assistant
Let me look at the agent runner
Assistant
Let me look at the runner.go and the tracer.go files.
Assistant
Now let me look at the tracer - this is what sends step state updates to the server
Assistant
Let me look at how stopPod works in the kubernetes backend
Assistant
Let me check the default stop timeout and the flags
Assistant
Let me look at recent git history to understand what might have changed
Assistant
Let me search for changes related to the runtime or step handling
Assistant
There's a key commit:
60df1c618 Fix workflow hang on services (#6507). Let me look at that commit.Assistant
This commit is exactly about the issue! Let me look at the diff:
Assistant
Now I understand the issue. Let me look at the
WaitStepin the kubernetes backend more carefully and trace through the issue.The problem is in the Kubernetes backend's
WaitStepfunction. WhenDestroyWorkflowdeletes a service pod viastopPod, theWaitStepfunction (running in a detached goroutine) never detects the pod deletion because:- The informer only has
UpdateFuncregistered, notDeleteFunc - If the pod is already deleted when the informer starts, it won't be in the initial list
WaitStephangs until the workflow context times out
Let me verify this by checking the flow more carefully:
- The informer only has
Assistant
Now I have a clear understanding of the issue. Let me look at the full
WaitStepandTailStepimplementations to plan the fix.Assistant
Let me try using the correct command format.
Assistant
Let me look at the
TailStepfunction too:Assistant
Let me check the imports at the top of the file:
Assistant
Now I understand the problem completely. Let me check how Kubernetes API errors are used in the code
Assistant
Now I have a clear understanding of the issue and the fix needed. Let me implement the changes.
The problem is in
WaitStepandTailStepin the Kubernetes backend:- They only register
UpdateFuncon the informer, notDeleteFunc - When
DestroyWorkflowdeletes a service pod,WaitStepmay never detect it because:- If the pod is deleted before the informer syncs, no event fires
- If the pod deletion doesn't trigger an update with a terminal phase
- After the select, if the pod is not found (404), it returns an error instead of treating it as a terminal state
Let me fix both functions
- They only register
Assistant
Let me try a different approach - I'll create a script to make the changes
Assistant
Let me verify the changes and also fix the
TailStepfunction similarlyAssistant
Good,
WaitStepchanges look correct. Now let me fixTailStepto add aDeleteFunctooAssistant
Now let me fix
TailStepwith the same approach - addDeleteFuncand handle pod deletionAssistant
Let me verify the changes look correct
Assistant
Let me check the TailStep changes
Assistant
Let me verify the imports are correct
Assistant
The changes look correct. Let me verify the code compiles correctly
Assistant
Let me set up the Go environment and try building
Assistant
Let me set up proper Go environment variables
Assistant
The code compiles. Let me also verify the full pipeline and agent compile
Assistant
Good, everything compiles. Let me run the existing tests to make sure nothing is broken
Assistant
Let me run all kubernetes backend tests
Assistant
All kubernetes tests pass. Let me also run the runtime tests
Assistant
Let me check with verbose
Assistant
Let me check the runtime directory
Assistant
The test files exist. Let me check why go test says no test files. Maybe the package name doesn't match.
Assistant
Let me check the package declaration in the test files
Assistant
Let me check the package line.
Assistant
Let me check for build constraints
Assistant
The test file has a build tag
//go:build test. Let me run with the proper tag:Assistant
All tests pass. Let me specifically check the key test for this issue
Assistant
All tests pass. Let me verify the final diff of my
Assistant
The changes look comprehensive. Let me verify one more time that everything compiles correctly
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.