From 402b3ba00fd22a90e3cc7243d07d3d8227309d10 Mon Sep 17 00:00:00 2001 From: mononaut Date: Fri, 24 Jul 2026 21:06:48 +0000 Subject: [PATCH] clean up stale unix sockets --- backend/src/index.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/src/index.ts b/backend/src/index.ts index e857a377b..04690c4bc 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,5 +1,6 @@ import express from 'express'; import { Application, Request, Response, NextFunction } from 'express'; +import * as fs from 'fs'; import * as http from 'http'; import * as WebSocket from 'ws'; import bitcoinApi from './api/bitcoin/bitcoin-api-factory'; @@ -67,6 +68,10 @@ class Server { constructor() { this.app = express(); + if (cluster.isPrimary && config.MEMPOOL.UNIX_SOCKET_PATH) { + this.clearStaleUnixSocket(config.MEMPOOL.UNIX_SOCKET_PATH); + } + if (!config.MEMPOOL.SPAWN_CLUSTER_PROCS) { void this.startServer(); return; @@ -249,6 +254,17 @@ class Server { void poolsUpdater.$startService(); } + clearStaleUnixSocket(path: string): void { + try { + if (fs.existsSync(path)) { + fs.unlinkSync(path); + logger.notice(`Removed stale unix socket ${path}`); + } + } catch (e) { + logger.err(`Failed to remove stale unix socket ${path}. Reason: ${e instanceof Error ? e.message : e}`); + } + } + /** @asyncSafe */ async runMainUpdateLoop(): Promise { const start = Date.now();