From 700e913b6a8d9360266672133fa35adc39307c71 Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Tue, 18 Jul 2023 13:09:39 +0200 Subject: [PATCH] Fix startup crash if the specified socket already exists --- src/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/index.ts b/src/index.ts index e4d8b01..bb6b185 100755 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,16 @@ import { env } from "process"; import { app, logger } from "./app"; import http from "http"; +import { existsSync, rmSync } from "fs"; const server = http.createServer(app); if (process.env.SOCKET_PATH != null && process.env.SOCKET_PATH.length > 0) { + // Remove the socket at the specified path if it already exists to avoid EADDRINUSE + if (existsSync(process.env.SOCKET_PATH)) { + rmSync(process.env.SOCKET_PATH); + } + server.listen({ path: process.env.SOCKET_PATH, readableAll: true,