Skip to content

Commit 48d7b3e

Browse files
committed
fix: remove eager WebSocket reconnect on SSH PID change
Server-side heartbeat (15s ping) already handles dead connections. WebSockets use a separate HTTPS path from the SSH tunnel, so PID changes don't reliably indicate WebSocket issues.
1 parent ec63c8a commit 48d7b3e

File tree

4 files changed

+2
-59
lines changed

4 files changed

+2
-59
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
### Fixed
66

7-
- SSH connections now recover faster after laptop sleep/wake by detecting port changes,
8-
re-registering the label formatter, and refreshing WebSockets automatically.
7+
- SSH connections now recover faster after laptop sleep/wake by detecting port changes
8+
and re-registering the label formatter.
99
- SSH process discovery now uses `ss` -> `netstat` -> `lsof` on Linux
1010
and `netstat` -> `lsof` on macOS, fixing systems where `netstat` was unavailable
1111
and the SSH PID could not be resolved, which broke network info display and log viewing.

src/api/coderApi.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,23 +154,6 @@ export class CoderApi extends Api implements vscode.Disposable {
154154
this.setCredentials(host, this.getSessionToken());
155155
};
156156

157-
/**
158-
* Force-reconnect all sockets in CONNECTED state, which may be in a TCP
159-
* half-open state after sleep/wake. Sockets in other states (AWAITING_RETRY,
160-
* DISCONNECTED) are left alone as they already have their own retry logic.
161-
*/
162-
reconnectAllConnected(reason: string): void {
163-
const stale = [...this.reconnectingSockets].filter(
164-
(s) => s.state === ConnectionState.CONNECTED,
165-
);
166-
if (stale.length > 0) {
167-
this.output.info(`Reconnecting ${stale.length} WebSocket(s): ${reason}`);
168-
for (const socket of stale) {
169-
socket.reconnect();
170-
}
171-
}
172-
}
173-
174157
/**
175158
* Permanently dispose all WebSocket connections.
176159
* This clears handlers and prevents reconnection.

src/remote/remote.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,6 @@ export class Remote {
529529
// Re-register label formatter when SSH process reconnects after sleep/wake
530530
sshMonitor.onPidChange(() => {
531531
reregisterLabelFormatter();
532-
// Reconnect WebSockets that may be in TCP half-open state
533-
workspaceClient.reconnectAllConnected("SSH process changed");
534532
}),
535533
// Register the label formatter again because SSH overrides it!
536534
vscode.extensions.onDidChange(() => {

test/unit/api/coderApi.test.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -795,44 +795,6 @@ describe("CoderApi", () => {
795795
});
796796
});
797797

798-
describe("reconnectAllConnected", () => {
799-
const tick = () => new Promise((resolve) => setImmediate(resolve));
800-
801-
it("reconnects sockets in CONNECTED state", async () => {
802-
const { sockets } = setupAutoOpeningWebSocket();
803-
api = createApi(CODER_URL, AXIOS_TOKEN);
804-
await api.watchAgentMetadata(AGENT_ID);
805-
await tick();
806-
807-
api.reconnectAllConnected("sleep/wake recovery");
808-
await tick();
809-
810-
expect(sockets[0].close).toHaveBeenCalledWith(
811-
1000,
812-
"Replacing connection",
813-
);
814-
expect(sockets).toHaveLength(2);
815-
});
816-
817-
it.each([
818-
["AWAITING_RETRY", 1006, "Abnormal closure"],
819-
["DISCONNECTED", 1002, "Protocol error"],
820-
])("does not reconnect %s sockets", async (_state, code, reason) => {
821-
const { sockets, handlers } = setupAutoOpeningWebSocket();
822-
api = createApi(CODER_URL, AXIOS_TOKEN);
823-
await api.watchAgentMetadata(AGENT_ID);
824-
await tick();
825-
826-
handlers["close"]?.({ code, reason });
827-
await tick();
828-
829-
api.reconnectAllConnected("sleep/wake recovery");
830-
await tick();
831-
832-
expect(sockets).toHaveLength(1);
833-
});
834-
});
835-
836798
describe("Configuration Change Reconnection", () => {
837799
const tick = () => new Promise((resolve) => setImmediate(resolve));
838800

0 commit comments

Comments
 (0)