From 7c52c68a88b678e7088843c976a63f79dfaa0f21 Mon Sep 17 00:00:00 2001 From: pbca26 Date: Sun, 3 Dec 2017 17:45:55 +0300 Subject: [PATCH] spv socket timeout 10s --- routes/electrumjs/electrumjs.core.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/routes/electrumjs/electrumjs.core.js b/routes/electrumjs/electrumjs.core.js index 82e73de..282cd12 100644 --- a/routes/electrumjs/electrumjs.core.js +++ b/routes/electrumjs/electrumjs.core.js @@ -25,6 +25,7 @@ SOFTWARE. const tls = require('tls'); const net = require('net'); const EventEmitter = require('events').EventEmitter; +const SOCKET_MAX_TIMEOUT = 10000; const makeRequest = function(method, params, id) { return JSON.stringify({ @@ -128,6 +129,12 @@ const getSocket = function(protocol, options) { const initSocket = function(self, protocol, options) { const conn = getSocket(protocol, options); + conn.setTimeout(SOCKET_MAX_TIMEOUT); + conn.on('timeout', () => { + console.log('socket timeout'); + self.onError(new Error('socket timeout')); + self.onClose(); + }); conn.setEncoding('utf8'); conn.setKeepAlive(true, 0); conn.setNoDelay(true);