Skip to content

Commit e4c7f05

Browse files
author
Alberto Iannaccone
committed
fix hanging web socket connections
1 parent 7fbcf33 commit e4c7f05

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

arduino-ide-extension/src/browser/monitor-manager-proxy-client-impl.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export class MonitorManagerProxyClientImpl
5858
* @param addressPort port of the WebSocket
5959
*/
6060
async connect(addressPort: number): Promise<void> {
61-
if (!!this.webSocket && this.wsPort === addressPort) return;
61+
if (!!this.webSocket) {
62+
if (this.wsPort === addressPort) return;
63+
else this.disconnect();
64+
}
6265
try {
6366
this.webSocket = new WebSocket(`ws://localhost:${addressPort}`);
6467
} catch {
@@ -84,6 +87,7 @@ export class MonitorManagerProxyClientImpl
8487
* Disconnects the WebSocket if connected.
8588
*/
8689
disconnect(): void {
90+
if (!this.webSocket) return;
8791
try {
8892
this.webSocket?.close();
8993
this.webSocket = undefined;

arduino-ide-extension/src/browser/serial/monitor/monitor-view-contribution.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ export class MonitorViewContribution
137137

138138
protected async reset(): Promise<void> {
139139
const widget = this.tryGetWidget();
140-
if (widget) widget.dispose();
141-
await this.openView({ activate: true, reveal: true });
140+
if (widget) {
141+
widget.dispose();
142+
await this.openView({ activate: true, reveal: true });
143+
}
142144
}
143145

144146
protected renderAutoScrollButton(): React.ReactNode {

arduino-ide-extension/src/node/monitor-service.ts

+3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ export class MonitorService extends CoreClientAware implements Disposable {
7575
// data from this monitor, we can freely close
7676
// and dispose it.
7777
this.dispose();
78+
return;
7879
}
80+
this.updateClientsSettings(this.settings);
7981
});
8082

8183
this.portMonitorSettings(port.protocol, board.fqbn!).then(
@@ -447,6 +449,7 @@ export class MonitorService extends CoreClientAware implements Disposable {
447449
}
448450

449451
updateClientsSettings(settings: MonitorSettings): void {
452+
this.settings = { ...this.settings, ...settings };
450453
const command: Monitor.Message = {
451454
command: Monitor.MiddlewareCommand.ON_SETTINGS_DID_CHANGE,
452455
data: settings,

0 commit comments

Comments
 (0)