Skip to content

Commit 9cff42c

Browse files
fix: error is raised when DevTools are closed while sending message
In case you open Chrome DevTools and close them while the iOS runtime still sends messages, an error is raised in CLI: ``` Error: WebSocket is not open: readyState 2 (CLOSING) ``` The problem is that we are using Transform stream between the communication and close event of the socket is not raised until the stream flushes its current state. Fix it by skipping the write operation in case the socket is not in OPEN state.
1 parent 2df6ae6 commit 9cff42c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/device-sockets/ios/app-debug-socket-proxy-factory.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu
138138
appDebugSocket.pipe(packets);
139139

140140
packets.on("data", (buffer: Buffer) => {
141-
webSocket.send(buffer.toString(encoding));
141+
const message = buffer.toString(encoding);
142+
if (webSocket.readyState === webSocket.OPEN) {
143+
webSocket.send(message);
144+
} else {
145+
this.$logger.trace(`Received message ${message}, but unable to send it to webSocket as its state is: ${webSocket.readyState}`);
146+
}
142147
});
143148

144149
webSocket.on("error", err => {

0 commit comments

Comments
 (0)