clean up stale unix sockets

This commit is contained in:
mononaut 2026-07-24 21:06:48 +00:00
parent e9d6cf8c04
commit 402b3ba00f
No known key found for this signature in database
GPG key ID: BFD16BE592A9CD8D

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();