Session lifecycle
This page describes what debugd does during a debug session, from the start request to the end. It is for operators and for users who want to understand the statuses in debugctl get sessions.
States
+--> FAILED
|
PENDING --> READY <--> UNRESPONSIVE
| ^
| +---> UNREACHABLE --> FAILED
|
+--> COMPLETED
+--> EXPIRED
| Status | Meaning | Final |
|---|---|---|
PENDING | debugd accepted the request and sets up the session. | No |
READY | Delve is attached, and its port is forwarded to localhost. | No |
UNRESPONSIVE | The Delve process runs, but its API does not answer. | No |
UNREACHABLE | debugd cannot reach the debug container, for example after a network change. The session can recover. | No |
COMPLETED | Delve stopped normally. | Yes |
EXPIRED | The session reached its time limit while it was healthy. | Yes |
FAILED | A step failed, Delve stopped with an error, or the debug container stopped. | Yes |
A session in a final status does not change again.
Start
- Admission.
debugdchecks the access token. Then it asks the DebugHero backend how many sessions you started in the last 24 hours and the last 7 days, and compares the numbers with the limits of your plan. If the backend cannot be reached,debugduses a local limit. If you reached a limit,debugdrejects the request with429. - Record.
debugdcreates the session with a new number (1, 2, 3, ...) and the statusPENDING. The numbers start at 1 each timedebugdstarts. - Set-up.
debugdruns the steps in How it works: find the pod, add the debug container, wait until it runs, find the process, start Delve, forward the ports, and find the build directory. - Ready. The status changes to
READY, anddebugdrecords the session in the DebugHero backend.
If a set-up step fails, the status changes to FAILED, and LAST_ERRORS contains the error. Warnings that do not stop the session, for example "falling back to pid 1", are also in LAST_ERRORS.
debugd waits for the debug container to run without a time limit. If the image cannot be pulled, the session stays PENDING.
While the session runs
debugd runs two checks in the background.
Container watch
Every 5 seconds (CONTAINER_WATCH_INTERVAL), debugd reads the status of the debug container from the Kubernetes API:
| Observation | Result |
|---|---|
| The debug container was OOM-killed | FAILED, reason oom_killed |
| The debug container stopped for another reason | FAILED, reason container_terminated_other |
| The pod does not exist anymore | FAILED, reason pod_disappeared |
Delve health
The server in the debug container starts and supervises Delve. Every 10 seconds (DLV_POLL_INTERVAL), debugd asks the server for the status of Delve. Then it sets READY, UNRESPONSIVE, UNREACHABLE, COMPLETED, EXPIRED or FAILED. If the server stays unreachable, the status changes to FAILED.
Authentication to the debug container
debugd sends your access token (Authorization: Bearer <token>) on each call to the server in the debug container. From image 0.0.8, the server rejects each call without a valid token. Only /health/check is open.
| Request | Result |
|---|---|
| No token, or a token that is not valid | 401 |
| A valid token of a different user | 403 |
| A valid token of the session owner | Accepted |
The first valid token sets the owner of the session. After that, only the owner can use the server.
Your token can expire during a session. The owner can continue to use an expired token on all routes except POST /v1/debug/dlv/start, until the server stops after SESSION_DURATION. To start Delve, the token must not be expired.
End
A session ends in one of these ways:
| Event | What happens |
|---|---|
| You stop the session | debugd asks the debug server to shut down. Delve removes its breakpoints and detaches, and your process continues to run. The debug container exits with code 0. debugd waits until the container is Terminated (up to 30 seconds). The session changes to COMPLETED with the reason stopped_by_user. |
| The debug container reaches its lifetime | The server in the debug container stops after SESSION_DURATION, 1 hour by default, and the container stops. The server first detaches Delve, and your process continues to run. |
| Delve stops | COMPLETED or FAILED, see Delve health. |
| The pod is deleted or replaced | FAILED with the reason pod_disappeared. |
debugd reaches its safety limit | debugd stops following a session after 3 hours. |
To stop a session, use Stop Session in the IDE, debugctl stop <session-id>, or POST /v1/debug/stop. When you only disconnect the IDE, the session continues.
The stop request returns one of these codes:
| Code | Meaning |
|---|---|
200 | The session stopped. The same code also comes when the session had already ended. |
404 | debugd does not know the session. |
409 | The session is still PENDING. Try again when it is READY. |
502 | The debug server does not answer. The session does not change, so you can try again. If the problem continues, restart the pod. |
In all the cases where the debug server stops normally (stop, lifetime, SIGTERM), Delve removes its breakpoints before it detaches. If the debug container is killed (for example, OOM), Delve cannot remove them, and the process can crash when it reaches one. Then restart the pod.
When a session ends, debugd closes its port-forwards.
Changes during a session
| Change | Effect |
|---|---|
debugd stops or restarts | debugd keeps sessions in memory only, so it forgets them. The port-forwards close. Delve can continue to run in the debug container until the container stops. |
| Your machine sleeps, or the network changes | The port-forwards can break. The session changes to UNREACHABLE and can recover. |
| The target container restarts | Delve stays attached to nothing: the new process is not attached. Start a new session. |
| The pod is replaced (rollout, eviction) | The debug container is removed with the pod. The session changes to FAILED. |
Debug container names
Kubernetes cannot remove an ephemeral container from a pod. Each session uses a new name: debughero- and 6 random characters, for example debughero-x7k2p9. Stopped containers stay in the pod spec, so you can start any number of sessions in sequence on the same pod.
Only one session at a time can debug a pod, because only one debugger can attach to a process. If a DebugHero container in the pod still runs, a new session changes to FAILED with the message "a debug session is already active on this pod". Stop the active session first.