Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed shell app timing out after ~50 secs #3135

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion apps/shell/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,22 @@ function detect_auth_error(requestToken, client_origin, server_origin, host) {
}
}

function noop() {}

function heartbeat() {
this.isAlive = true;
}

wss.on('connection', function connection (ws, req) {
var dir,
term,
args,
host,
cmd = process.env.OOD_SSH_WRAPPER || 'ssh';


ws.isAlive = true;
ws.on('pong', heartbeat);

console.log('Connection established');

[host, dir] = host_and_dir_from_url(req.url);
Expand All @@ -165,6 +174,7 @@ wss.on('connection', function connection (ws, req) {
cols: 80,
rows: 30
});


console.log('Opened terminal: ' + term.pid);

Expand Down Expand Up @@ -195,6 +205,15 @@ wss.on('connection', function connection (ws, req) {
}
});

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);
Expand Down