From b5f6919bab8da2c6eb7f23044ca59b8a06b806be Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 26 Nov 2023 17:51:26 +0800 Subject: [PATCH] Fix 100% cpu usage and terminal issue by downgrading Node.js to 18.17.1 (#186) * Downgrade from Node.js 20 to Node.js 18.17.1 * Enable back socket.io polling * Avoid multiple commands at the same for a stack --- backend/dockge-server.ts | 1 - backend/terminal.ts | 20 ++++++++++++-------- docker/Base.Dockerfile | 15 +-------------- frontend/src/mixins/socket.ts | 2 +- package.json | 3 +++ 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/backend/dockge-server.ts b/backend/dockge-server.ts index c4a358f..7aaba63 100644 --- a/backend/dockge-server.ts +++ b/backend/dockge-server.ts @@ -195,7 +195,6 @@ export class DockgeServer { // Create Socket.io this.io = new socketIO.Server(this.httpServer, { cors, - transports: [ "websocket" ], }); this.io.on("connection", async (socket: Socket) => { diff --git a/backend/terminal.ts b/backend/terminal.ts index 2b22e69..96a8b01 100644 --- a/backend/terminal.ts +++ b/backend/terminal.ts @@ -5,8 +5,6 @@ import { LimitQueue } from "./utils/limit-queue"; import { DockgeSocket } from "./util-server"; import { allowedCommandList, allowedRawKeys, - getComposeTerminalName, - getCryptoRandomInt, PROGRESS_TERMINAL_ROWS, TERMINAL_COLS, TERMINAL_ROWS @@ -207,14 +205,20 @@ export class Terminal { } public static exec(server : DockgeServer, socket : DockgeSocket | undefined, terminalName : string, file : string, args : string | string[], cwd : string) : Promise { - const terminal = new Terminal(server, terminalName, file, args, cwd); - terminal.rows = PROGRESS_TERMINAL_ROWS; + return new Promise((resolve, reject) => { + // check if terminal exists + if (Terminal.terminalMap.has(terminalName)) { + reject("Another operation is already running, please try again later."); + return; + } - if (socket) { - terminal.join(socket); - } + let terminal = new Terminal(server, terminalName, file, args, cwd); + terminal.rows = PROGRESS_TERMINAL_ROWS; + + if (socket) { + terminal.join(socket); + } - return new Promise((resolve) => { terminal.onExit((exitCode : number) => { resolve(exitCode); }); diff --git a/docker/Base.Dockerfile b/docker/Base.Dockerfile index 7c89d95..8707629 100644 --- a/docker/Base.Dockerfile +++ b/docker/Base.Dockerfile @@ -1,4 +1,4 @@ -FROM node:20-bookworm-slim +FROM node:18.17.1-bookworm-slim ENV PNPM_HOME="/pnpm" ENV PATH="$PNPM_HOME:$PATH" @@ -24,16 +24,3 @@ RUN apt update && apt install --yes --no-install-recommends \ && rm -rf /var/lib/apt/lists/* \ && npm install pnpm -g \ && pnpm install -g tsx - -# ensures that /var/run/docker.sock exists -# changes the ownership of /var/run/docker.sock -RUN touch /var/run/docker.sock && chown node:node /var/run/docker.sock - -# Full Base Image -# MariaDB, Chromium and fonts -#FROM base-slim AS base -#ENV DOCKGE_ENABLE_EMBEDDED_MARIADB=1 -#RUN apt update && \ -# apt --yes --no-install-recommends install mariadb-server && \ -# rm -rf /var/lib/apt/lists/* && \ -# apt --yes autoremove diff --git a/frontend/src/mixins/socket.ts b/frontend/src/mixins/socket.ts index c85da3c..30c74e7 100644 --- a/frontend/src/mixins/socket.ts +++ b/frontend/src/mixins/socket.ts @@ -109,7 +109,7 @@ export default defineComponent({ }, 1500); socket = io(url, { - transports: [ "websocket" ] + transports: [ "websocket", "polling" ] }); socket.on("connect", () => { diff --git a/package.json b/package.json index dc22b45..b9d5785 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,9 @@ "name": "dockge", "version": "1.1.1", "type": "module", + "engines": { + "node": ">= 18.0.0 && <= 18.17.1" + }, "scripts": { "fmt": "eslint \"**/*.{ts,vue}\" --fix", "lint": "eslint \"**/*.{ts,vue}\"",