Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

### Changed

- WebSocket connections are now more robust and reconnect less frequently, only when truly
necessary, reducing unnecessary disconnections and improving stability.

## [v1.12.1](https://github.com/coder/vscode-coder/releases/tag/v1.12.1) 2026-01-23

### Fixed
Expand Down
16 changes: 11 additions & 5 deletions src/api/coderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
type OneWayWebSocketInit,
} from "../websocket/oneWayWebSocket";
import {
ConnectionState,
ReconnectingWebSocket,
type SocketFactory,
} from "../websocket/reconnectingWebSocket";
Expand Down Expand Up @@ -164,19 +165,24 @@ export class CoderApi extends Api implements vscode.Disposable {

/**
* Watch for configuration changes that affect WebSocket connections.
* When any watched setting changes, all active WebSockets are reconnected.
* Only reconnects DISCONNECTED sockets since they require an explicit reconnect() call.
* Other states will pick up settings naturally.
*/
private watchConfigChanges(): vscode.Disposable {
const settings = webSocketConfigSettings.map((setting) => ({
setting,
getValue: () => vscode.workspace.getConfiguration().get(setting),
}));
return watchConfigurationChanges(settings, () => {
if (this.reconnectingSockets.size > 0) {
this.output.info(
`Configuration changed, reconnecting ${this.reconnectingSockets.size} WebSocket(s)`,
const socketsToReconnect = [...this.reconnectingSockets].filter(
(socket) => socket.state === ConnectionState.DISCONNECTED,
);
if (socketsToReconnect.length) {
this.output.debug(
`Configuration changed, ${socketsToReconnect.length}/${this.reconnectingSockets.size} socket(s) in DISCONNECTED state`,
);
for (const socket of this.reconnectingSockets) {
for (const socket of socketsToReconnect) {
this.output.debug(`Reconnecting WebSocket: ${socket.url}`);
socket.reconnect();
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ export class Inbox implements vscode.Disposable {
logger.info("Listening to Coder Inbox");
});

socket.addEventListener("error", () => {
// Errors are already logged internally
inbox.dispose();
});

socket.addEventListener("message", (data) => {
if (data.parseError) {
logger.error("Failed to parse inbox message", data.parseError);
Expand Down
Loading