From 7a098952c8e79dc24732771ae5723194c3d3c1e5 Mon Sep 17 00:00:00 2001 From: nymkappa <1612910616@pm.me> Date: Tue, 9 Apr 2024 15:11:40 +0900 Subject: [PATCH] [server] disable unix socket listening by default --- backend/mempool-config.sample.json | 3 ++- backend/src/config.ts | 2 +- backend/src/index.ts | 26 ++++++++++++++++---------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/backend/mempool-config.sample.json b/backend/mempool-config.sample.json index c93774fba..87f9d5f34 100644 --- a/backend/mempool-config.sample.json +++ b/backend/mempool-config.sample.json @@ -35,7 +35,8 @@ "MAX_PUSH_TX_SIZE_WEIGHT": 4000000, "ALLOW_UNREACHABLE": true, "PRICE_UPDATES_PER_HOUR": 1, - "MAX_TRACKED_ADDRESSES": 100 + "MAX_TRACKED_ADDRESSES": 100, + "UNIX_SOCKET_PATH": "" }, "CORE_RPC": { "HOST": "127.0.0.1", diff --git a/backend/src/config.ts b/backend/src/config.ts index daaca34ba..ae56e4b91 100644 --- a/backend/src/config.ts +++ b/backend/src/config.ts @@ -165,7 +165,7 @@ const defaults: IConfig = { 'NETWORK': 'mainnet', 'BACKEND': 'none', 'HTTP_PORT': 8999, - 'UNIX_SOCKET_PATH': '/mempool/socket/mempool-bitcoin-mainnet', + 'UNIX_SOCKET_PATH': '', 'SPAWN_CLUSTER_PROCS': 0, 'API_URL_PREFIX': '/api/v1/', 'POLL_RATE_MS': 2000, diff --git a/backend/src/index.ts b/backend/src/index.ts index 3840afa10..b088155ea 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -138,9 +138,11 @@ class Server { } this.server = http.createServer(this.app); - this.serverUnixSocket = http.createServer(this.app); this.wss = new WebSocket.Server({ server: this.server }); - this.wssUnixSocket = new WebSocket.Server({ server: this.serverUnixSocket }); + if (config.MEMPOOL.UNIX_SOCKET_PATH) { + this.serverUnixSocket = http.createServer(this.app); + this.wssUnixSocket = new WebSocket.Server({ server: this.serverUnixSocket }); + } this.setUpWebsocketHandling(); @@ -197,13 +199,15 @@ class Server { } }); - this.serverUnixSocket.listen(config.MEMPOOL.UNIX_SOCKET_PATH, () => { - if (worker) { - logger.info(`Mempool Server worker #${process.pid} started`); - } else { - logger.notice(`Mempool Server is listening on ${config.MEMPOOL.UNIX_SOCKET_PATH}`); - } - }); + if (this.serverUnixSocket) { + this.serverUnixSocket.listen(config.MEMPOOL.UNIX_SOCKET_PATH, () => { + if (worker) { + logger.info(`Mempool Server worker #${process.pid} started`); + } else { + logger.notice(`Mempool Server is listening on ${config.MEMPOOL.UNIX_SOCKET_PATH}`); + } + }); + } } async runMainUpdateLoop(): Promise { @@ -357,7 +361,9 @@ class Server { this.server?.close(); this.serverUnixSocket?.close(); this.wss?.close(); - this.wssUnixSocket?.close(); + if (this.wssUnixSocket) { + this.wssUnixSocket.close(); + } process.exit(code); }