From 71ffc122d65e3c0dfe2d034284946a836f2b93c8 Mon Sep 17 00:00:00 2001 From: Bronwen Date: Sun, 14 Feb 2021 02:03:26 -0500 Subject: [PATCH] back off steps and eaddress in use --- lib/STP/index.js | 4 ++++ relay/index.js | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/STP/index.js b/lib/STP/index.js index 077882d..a718db5 100644 --- a/lib/STP/index.js +++ b/lib/STP/index.js @@ -39,6 +39,10 @@ class Server extends EventEmitter { openServer() { log.info(`opening STP server on ${this.port}`); this.tcpServer = net.createServer(this.tcpConnectClient.bind(this)); + this.tcpServer.on('error', e => { + log.warn(e) + setTimeout(this.openServer.bind(this), 5000); + }) this.tcpServer.listen(this.port); } diff --git a/relay/index.js b/relay/index.js index 2da8804..fe6c8de 100644 --- a/relay/index.js +++ b/relay/index.js @@ -39,7 +39,8 @@ function connectNetwork(t = 1000) { client.on('error', e => { }); client.on('close', e => { - setTimeout(connectNetwork.bind(global, t*2), t); + t *= 2; + setTimeout(connectNetwork.bind(global, t), t); log.debug('retrying connection... ' + (t/1000) + 's') }); } @@ -52,14 +53,18 @@ const app = express(); app.get('/', (req, res) => { res.end(` @@ -89,7 +94,14 @@ app.get('/', (req, res) => { // app.post -app.listen(8080); +app.listen(8080).on('error', e => { + log.warn(e); + setTimeout(_ => { + app.listen(8080).on('error', e => { + log.error(e); + }); + }, 5000); +});