ondemand icon indicating copy to clipboard operation
ondemand copied to clipboard

Shell Access disconnects quickly

Open barche opened this issue 2 years ago • 1 comments

Hi, I am running ondemand-2.1.20220901-127532.4b5f020.nightly.el9.x86_64 and the shell app (under the "Clusters" tab) disconnects often after less than a minute of inactivity. I'm not sure why, since as far as I can tell there are no errors in the logs. I didn't change anything from the default config for this application.

┆Issue is synchronized with this Asana task by Unito

barche avatar Sep 05 '22 11:09 barche

Hi, thanks for the ticket. I'm not sure what the timeouts are, but I don't believe we implement ping/pong to keep it alive either.

Which is to say, thanks for the ticket.

johrstrom avatar Sep 06 '22 13:09 johrstrom

I can confirm the patch from the linked issue above solves this for me, diff for OOD 3.0.3 shell app.js:

--- app.js_orig 2023-10-24 17:03:42.376562196 +0200
+++ app.js      2023-10-24 17:03:49.445438516 +0200
@@ -96,6 +96,12 @@
   return [hostname, directory];
 }

+function noop() {}
+
+function heartbeat() {
+  this.isAlive = true;
+}
+
 function custom_server_origin(default_value = null){
   var custom_origin = null;

@@ -188,6 +194,9 @@
       if (msg.resize) term.resize(parseInt(msg.resize.cols), parseInt(msg.resize.rows));
     });

+    ws.isAlive = true;
+    ws.on('pong', heartbeat);
+
     ws.on('close', function () {
       term.end();
       console.log('Closed terminal: ' + term.pid);
@@ -195,6 +204,14 @@
   }
 });

+const interval = setInterval(function ping() {
+         wss.clients.forEach(function each(ws) {
+                     if (ws.isAlive === false) return ws.terminate();
+                     ws.isAlive = false;
+                     ws.ping(noop);
+                   });
+}, 30000);
+
 server.on('upgrade', function upgrade(request, socket, head) {
   wss.handleUpgrade(request, socket, head, function done(ws) {
     wss.emit('connection', ws, request);

barche avatar Oct 24 '23 15:10 barche

Thanks! pull requests (and/or git diff's) welcome! I'll try to put this in 3.1 - the next release.

johrstrom avatar Oct 24 '23 15:10 johrstrom

@wtripp180901 do you want to make a PR for ondemand with this? I can do it too, but it's your code :)

barche avatar Oct 24 '23 16:10 barche

Yeah sure I'll put one in

wtripp180901 avatar Oct 25 '23 09:10 wtripp180901