From ff2ea805c0fc2ea6079ba441de261643f983a324 Mon Sep 17 00:00:00 2001 From: Nishan Date: Sat, 12 Apr 2025 16:26:07 +0530 Subject: [PATCH] force polling for terminal --- app/package.json | 2 +- app/public/js/components/terminal-service.js | 9 ++++++++- docker-compose.yaml | 2 +- nginx/default.conf | 17 ----------------- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/app/package.json b/app/package.json index 9c31177..62ac520 100644 --- a/app/package.json +++ b/app/package.json @@ -11,7 +11,7 @@ "cors": "^2.8.5", "express": "^4.21.2", "http-proxy-middleware": "^2.0.7", - "socket.io": "^4.7.2", + "socket.io": "4.7.2", "ssh2": "^1.14.0", "xterm": "^5.3.0" }, diff --git a/app/public/js/components/terminal-service.js b/app/public/js/components/terminal-service.js index 1ee1287..5b0f9c9 100644 --- a/app/public/js/components/terminal-service.js +++ b/app/public/js/components/terminal-service.js @@ -153,7 +153,8 @@ function connectToSocketIO() { socket = io('/ssh', { forceNew: true, reconnectionAttempts: 1000, - timeout: 1000 + timeout: 1000, + transports: ['polling'] // force polling for now to avoid invalid frame error , TODO: fix this }); console.log('Creating new socket connection to SSH server'); @@ -199,6 +200,12 @@ function connectToSocketIO() { if (terminal) { terminal.writeln(`\r\n\x1b[1;31m[ERROR]\x1b[0m ${err.message}\r\n`); } + // try to reconnect + setTimeout(() => { + if (socket && !socket.connected) { + socket.connect(); + } + }, 2000); }); // Handle SSH data with processing for ANSI codes diff --git a/docker-compose.yaml b/docker-compose.yaml index 44eea2f..f87bfcf 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -212,7 +212,7 @@ services: - LOG_LEVEL=info - REDIS_HOST=redis - REDIS_PORT=6379 - - TRACK_METRICS=false # based on the environment variable TRACK_METRICS, the facilitator will send metrics to the metric server + - TRACK_METRICS=true # based on the environment variable TRACK_METRICS, the facilitator will send metrics to the metric server restart: unless-stopped depends_on: - jumphost diff --git a/nginx/default.conf b/nginx/default.conf index bd9cda8..2b06ab6 100644 --- a/nginx/default.conf +++ b/nginx/default.conf @@ -20,23 +20,6 @@ server { proxy_cache_bypass $http_upgrade; } - location /ssh/socket.io/ { - proxy_pass http://webapp:3000/ssh/socket.io/; - - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - - proxy_read_timeout 86400; - proxy_send_timeout 86400; - - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Real-IP $remote_addr; - proxy_buffering off; - } - # Facilitator API endpoint location /facilitator/api/ { proxy_pass http://facilitator:3000/api/;