feat: improve coder connect tunnel handling on reconnect#17598
Merged
ibetitsmike merged 10 commits intoMay 6, 2025
Conversation
f66d81a to
52f1c2b
Compare
johnstcn
reviewed
Apr 30, 2025
Member
johnstcn
left a comment
There was a problem hiding this comment.
I'm lacking context on what this change fixes. The code itself looks fine and the test coverage checks out, but deferring to Dean and Spike.
…te never has them)
deansheather
approved these changes
May 1, 2025
spikecurtis
requested changes
May 1, 2025
spikecurtis
approved these changes
May 6, 2025
| delete(u.agents, agent.ID) | ||
| } | ||
| for _, workspace := range update.UpsertedWorkspaces { | ||
| u.workspaces[workspace.ID] = workspace.Clone() |
Contributor
There was a problem hiding this comment.
We don't actually need a full clone of the workspace, but it's probably clearer to do the legit Clone so we don't have a partially cloned object waiting to trip up some future editor of this code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes coder/internal#563
The Coder Connect tunnel receives workspace state from the Coder server over a dRPC stream. When first connecting to this stream, the current state of the user's workspaces is received, with subsequent messages being diffs on top of that state.
However, if the client disconnects from this stream, such as when the user's device is suspended, and then reconnects later, no mechanism exists for the tunnel to differentiate that message containing the entire initial state from another diff, and so that state is incorrectly applied as a diff.
In practice:
This PR introduces a solution in which tunnelUpdater, when created, sends a FreshState flag with the WorkspaceUpdate type. This flag is handled in the vpn tunnel in the following fashion: