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
4 changes: 2 additions & 2 deletions ts/src/connections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"buffer": "^5.2.1",
"debug": "^4.1.1",
"vscode-jsonrpc": "^4.0.0",
"@microsoft/dev-tunnels-contracts": ">1.1.9",
"@microsoft/dev-tunnels-management": ">1.1.9",
"@microsoft/dev-tunnels-contracts": ">1.1.10",
"@microsoft/dev-tunnels-management": ">1.1.10",
"@microsoft/dev-tunnels-ssh": "^3.11.36",
"@microsoft/dev-tunnels-ssh-tcp": "^3.11.36",
"uuid": "^3.3.3",
Expand Down
2 changes: 1 addition & 1 deletion ts/src/connections/relayTunnelConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { TunnelConnectionOptions } from './tunnelConnectionOptions';
export const maxReconnectDelayMs = 13000;

// Delay between the 1st and the 2nd attempts.
const reconnectInitialDelayMs = 100;
const reconnectInitialDelayMs = 1000;

// There is no status code information in web socket errors in browser context.
// Instead, connection will retry anyway with limited retry attempts.
Expand Down
12 changes: 10 additions & 2 deletions ts/src/connections/sshHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class SshHelpers {
if (isNode()) {
return SshHelpers.nodeSshStreamFactory(relayUri, protocols, headers, clientConfig);
}

return SshHelpers.webSshStreamFactory(new WebSocket(relayUri, protocols));
}

Expand Down Expand Up @@ -101,6 +100,7 @@ export class SshHelpers {
public static webSshStreamFactory(socket: WebSocket): Promise<ssh.WebSocketStream> {
socket.binaryType = 'arraybuffer';
return new Promise<ssh.WebSocketStream>((resolve, reject) => {
const relayError = 'Failed to connect to relay url';
socket.onopen = () => {
resolve(new ssh.WebSocketStream(socket));
};
Expand All @@ -109,7 +109,15 @@ export class SshHelpers {
// the user agents must not convey extended error information including the cases where the server
// didn't complete the opening handshake (e.g. because it was not a WebSocket server).
// So we cannot obtain the response status code.
reject(new BrowserWebSocketRelayError(`Failed to connect to relay url`));
// Note: When the socket is connected and an error occurs then `onclose` event occurs after `onerror`.
// However, the promise is already rejected by `onerror` and we loose this information, hence the
// timeout helps to give us some info in this scenario.
setTimeout(() => reject(new BrowserWebSocketRelayError(relayError)), 100);
};
socket.onclose = (e) => {
if (e.code !== 1000) {
reject(new BrowserWebSocketRelayError(`${relayError} Code: ${e.code} Reason: ${e.reason}`));
}
};
});
}
Expand Down
2 changes: 1 addition & 1 deletion ts/src/management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"buffer": "^5.2.1",
"debug": "^4.1.1",
"vscode-jsonrpc": "^4.0.0",
"@microsoft/dev-tunnels-contracts": ">1.1.9",
"@microsoft/dev-tunnels-contracts": ">1.1.10",
"axios": "^1.6.6"
}
}