Skip to content

Commit 4d85241

Browse files
committed
Add connection guard to prevent overlapping requests
1 parent 2bccc88 commit 4d85241

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/js/serial_backend.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ export function initializeSerialBackend() {
6161

6262
EventBus.$on("port-handler:auto-select-serial-device", function () {
6363
if (
64-
!GUI.connected_to &&
65-
!GUI.connecting_to &&
66-
!["cli", "firmware_flasher"].includes(GUI.active_tab) &&
67-
PortHandler.portPicker.autoConnect &&
68-
!isCliOnlyMode() &&
69-
(connectionTimestamp === null || connectionTimestamp > 0) ||
70-
(Date.now() - rebootTimestamp <= REBOOT_CONNECT_MAX_TIME_MS)
64+
(!GUI.connected_to &&
65+
!GUI.connecting_to &&
66+
!["cli", "firmware_flasher"].includes(GUI.active_tab) &&
67+
PortHandler.portPicker.autoConnect &&
68+
!isCliOnlyMode() &&
69+
(connectionTimestamp === null || connectionTimestamp > 0)) ||
70+
Date.now() - rebootTimestamp <= REBOOT_CONNECT_MAX_TIME_MS
7171
) {
7272
connectDisconnect();
7373
}
@@ -152,11 +152,16 @@ function connectDisconnect() {
152152
serial.addEventListener("disconnect", disconnectHandler);
153153
}
154154

155-
serial.connect(
156-
portName,
157-
{ baudRate: PortHandler.portPicker.selectedBauds },
158-
selectedPort === "virtual" ? onOpenVirtual : undefined,
159-
);
155+
GUI.connect_lock = true;
156+
serial
157+
.connect(
158+
portName,
159+
{ baudRate: PortHandler.portPicker.selectedBauds },
160+
selectedPort === "virtual" ? onOpenVirtual : undefined,
161+
)
162+
.finally(() => {
163+
GUI.connect_lock = false;
164+
});
160165
}
161166

162167
// show CLI panel on Control+I

0 commit comments

Comments
 (0)