wassh: fix showing popup on disconnection when using relay by returning error when writing to a closed relay socket
When the ssh connection drops in nassh, pressing any key will show the "Process exited" dialog, with options to reconnect or exit.
This works on NaCL, and on wassh with direct connections, but not with relays: pressing keys after the connection drops does nothing.
Listen for the disconnection event from the relay stream, and manually force a connection reset error on subsequent writes.
Screenshot: https://drive.google.com/file/d/1hJxEQzKab10rwCFtqDJ4jTO46mB2Ud6r/view?usp=sharing
I connected to my computer via a websockify relay, then force closed the sshd to terminate the connection.
Pressing a key then shows the "Process exited" dialog, like what happens without a relay / what happens in NaCL.
Change-Id: I181543b8687bf6c208a2603904aea032999df0af
Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/6027492
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Joel Hockey <joelhockey@chromium.org>
diff --git a/wassh/js/sockets.js b/wassh/js/sockets.js
index 651e691..10c8570 100644
--- a/wassh/js/sockets.js
+++ b/wassh/js/sockets.js
@@ -963,6 +963,10 @@
}
this.callback_.onDataAvailable = (data) => this.onRecv(data);
+ this.callback_.onClose = () => {
+ this.callback_ = null;
+ this.close();
+ };
this.address = address;
this.port = port;
return WASI.errno.ESUCCESS;
@@ -984,6 +988,9 @@
/** @override */
async write(buf) {
+ if (!this.callback_) {
+ return WASI.errno.ECONNRESET;
+ }
await this.callback_.asyncWrite(buf);
return {nwritten: buf.length};
}