Skip to main content

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​

Session states
+--> FAILED
|
PENDING --> READY <--> UNRESPONSIVE
| ^
| +---> UNREACHABLE --> FAILED
|
+--> COMPLETED
+--> EXPIRED
StatusMeaningFinal
PENDINGdebugd accepted the request and sets up the session.No
READYDelve is attached, and its port is forwarded to localhost.No
UNRESPONSIVEThe Delve process runs, but its API does not answer.No
UNREACHABLEdebugd cannot reach the debug container, for example after a network change. The session can recover.No
COMPLETEDDelve stopped normally.Yes
EXPIREDThe session reached its time limit while it was healthy.Yes
FAILEDA step failed, Delve stopped with an error, or the debug container stopped.Yes

A session in a final status does not change again.

Start​

  1. Admission. debugd checks 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, debugd uses a local limit. If you reached a limit, debugd rejects the request with 429.
  2. Record. debugd creates the session with a new number (1, 2, 3, ...) and the status PENDING. The numbers start at 1 each time debugd starts.
  3. Set-up. debugd runs 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.
  4. Ready. The status changes to READY, and debugd records 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:

ObservationResult
The debug container was OOM-killedFAILED, reason oom_killed
The debug container stopped for another reasonFAILED, reason container_terminated_other
The pod does not exist anymoreFAILED, 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.

RequestResult
No token, or a token that is not valid401
A valid token of a different user403
A valid token of the session ownerAccepted

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:

EventWhat happens
You stop the sessiondebugd 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 lifetimeThe 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 stopsCOMPLETED or FAILED, see Delve health.
The pod is deleted or replacedFAILED with the reason pod_disappeared.
debugd reaches its safety limitdebugd 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:

CodeMeaning
200The session stopped. The same code also comes when the session had already ended.
404debugd does not know the session.
409The session is still PENDING. Try again when it is READY.
502The 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​

ChangeEffect
debugd stops or restartsdebugd 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 changesThe port-forwards can break. The session changes to UNREACHABLE and can recover.
The target container restartsDelve 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.