Merge pull request #6656 from mempool/mononaut/clean-unix-socket
Some checks failed
Backend Integration Tests with MariaDB / Backend Integration Tests - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Backend (dev) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Backend (prod) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Cache assets for builds (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Validate generated backend Docker JSON (push) Has been cancelled
Supply Chain Audit / Backend install-script audit (push) Has been cancelled
Supply Chain Audit / Frontend install-script audit (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Frontend (dev) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / Frontend (prod) - node 24.13.0 (push) Has been cancelled
CI Pipeline for the Backend and Frontend / E2E tests for liquid (push) Has been cancelled
CI Pipeline for the Backend and Frontend / E2E tests for mempool (push) Has been cancelled
CI Pipeline for the Backend and Frontend / E2E tests for testnet4 (push) Has been cancelled

This commit is contained in:
wiz 2026-07-25 13:48:51 +09:00 committed by GitHub
commit 87f14d25f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<void> {
const start = Date.now();