Skip to content

Commit 617790b

Browse files
authored
Prevent closing serial twice on reboot (#3990)
1 parent ff83600 commit 617790b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/js/webSerial.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class WebSerial extends EventTarget {
2020
this.connected = false;
2121
this.openRequested = false;
2222
this.openCanceled = false;
23+
this.closeRequested = false;
2324
this.transmitting = false;
2425
this.connectionInfo = null;
2526

@@ -66,6 +67,7 @@ class WebSerial extends EventTarget {
6667

6768
handleDisconnect() {
6869
this.disconnect();
70+
this.closeRequested = true;
6971
}
7072

7173
getConnectedPort() {
@@ -116,6 +118,7 @@ class WebSerial extends EventTarget {
116118

117119
async connect(path, options) {
118120
this.openRequested = true;
121+
this.closeRequested = false;
119122

120123
this.port = this.ports.find(device => device.path === path).port;
121124

@@ -191,6 +194,11 @@ class WebSerial extends EventTarget {
191194
this.bytesReceived = 0;
192195
this.bytesSent = 0;
193196

197+
// if we are already closing, don't do it again
198+
if (this.closeRequested) {
199+
return;
200+
}
201+
194202
const doCleanup = async () => {
195203
this.removeEventListener('receive', this.handleReceiveBytes);
196204
if (this.reader) {

0 commit comments

Comments
 (0)