- Notifications
You must be signed in to change notification settings - Fork1.1k
fix: stop disconnecting from coderd early and record disconnect correctly#21250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
spikecurtis commentedDec 12, 2025
This stack of pull requests is managed byGraphite. Learn more aboutstacking. |
mafredri left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Nice find!
We should simplify the defer in monitor, but otherwise logic seems sound, approving. 👍🏻
| ifclosing { | ||
| _=network.Close() | ||
| returnxerrors.New("agent is closing") | ||
| returnErrAgentClosing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Suggestion: Wrap error for consistency?
| Time:dbtime.Now(), | ||
| Valid:true, | ||
| } | ||
| }() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Perhaps a larger change than you were intending for, but wouldn't it make sense to combine these two defer's? In the current state they muddy the exit path of the routine.

Uh oh!
There was an error while loading.Please reload this page.
fixescoder/internal#1196
The above issue exposes two different bugs in Coder.
In the agent, there is a race where if the agent is closed while starting up networking, it will erroneously disconnect from Coderd, which delays or breaks writing final status and logs.
In Coderd, there is a bug where we don't properly record the latest agent disconnection time if the agent had previously disconnected. This causes us to report the agent status as "Connected" even after it has disconnected up until the inactivity timeout fires.
This PR fixes both issues.
It also slightly reworks when we send workspace updates based on connection and disconnection. Previously we would send two updates when the agent connected in certain circumstances, even though the status would be the same in both (only times changed). Now we universally only send one on connect, and then another on disconnect.