Node.js WebSocket错误:重新连接后读取ECONNRESET

时间:2018-03-06 11:00:01

标签: javascript node.js websocket

我的node.js客户端应用程序连接到第三方Websocket API,用于使用ws npm包连续发送/接收数据。有时连接由服务器关闭,因为短暂的服务中断(至少我相信这是原因)并且我的应用程序需要重新建立连接。

我在这篇文章中得到了一个很好的解决方案,它适用于一些重新连接,但随后我的应用程序崩溃了: (用户Yury Fedorov Node-js: Not receiving events after websocket reconnect):

const WS = require('ws');
var BFX = new WS('bfxs://api.uri.com/ws/2');

function createWebsocket() {
    const websocket = new BFX().ws(2, opts);
    websocket.on('open', /* code */);
    websocket.open();
}

并在on('close')中调用它:

websocket.on('close', ()=>{
     setTimeout(createWebsocket, 10000);
});

我得到的错误是:Error: read ECONNRESET

我安装了npm package longjohn以获得更长的堆栈跟踪,但我无法解释更长的堆栈跟踪:

    ________________________________________________________
        Error: read ECONNRESET
            at _errnoException (util.js:1022:11)
            at TLSWrap.onread (net.js:615:25)`
    ____________________________________________
        at TLSSocket.Readable.on (_stream_readable.js:772:35)
        at Ultron.on (/home/user/core/node_modules/ultron/index.js:42:11)
        at WebSocket.setSocket (/home/user/core/node_modules/ws/lib/WebSocket.js:131:18)
        at ClientRequest._req.on (/home/user/core/node_modules/ws/lib/WebSocket.js:715:10)
        at emitThree (events.js:136:13)
        at ClientRequest.emit (events.js:217:7)
        at TLSSocket.socketOnData (_http_client.js:472:11)
        at emitOne (events.js:116:13)
        at TLSSocket.emit (events.js:211:7)
        at addChunk (_stream_readable.js:263:12)
        at readableAddChunk (_stream_readable.js:250:11)
        at TLSSocket.Readable.push (_stream_readable.js:208:10)
        at TLSWrap.onread (net.js:594:20)
    ____________________________________________
        at WebSocket.initAsClient (/home/user/core/node_modules/ws/lib/WebSocket.js:657:13)
        at new WebSocket (/home/user/core/node_modules/ws/lib/WebSocket.js:72:20)
        at startWebsocket (/home/user/core/myApp.js:76:11)
        at Timeout.<anonymous> (/home/user/core/myApp.js:117:31)
        at ontimeout (timers.js:475:11)
        at tryOnTimeout (timers.js:310:5)
        at Timer.listOnTimeout (timers.js:270:5)
        ____________________________________________
        at WebSocket.bfx.onclose (/home/user/core/myApp.js:117:9)
        at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
        at emitTwo (events.js:126:13)
        at WebSocket.emit (events.js:214:7)
        at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
        at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
        at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
        at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
        at emitNone (events.js:111:20)
        at TLSSocket.emit (events.js:208:7)
        at endReadableNT (_stream_readable.js:1055:12)
        at _combinedTickCallback (internal/process/next_tick.js:138:11)
        at process._tickCallback (internal/process/next_tick.js:180:9)
    ____________________________________________
        at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
        at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
        at startWebsocket (/home/user/core/myApp.js:115:14)
        at Timeout.<anonymous> (/home/user/core/myApp.js:117:31)
        at ontimeout (timers.js:475:11)
        at tryOnTimeout (timers.js:310:5)
        at Timer.listOnTimeout (timers.js:270:5)
    ____________________________________________
        at WebSocket.bfx.onclose (/home/user/core/myApp.js:117:9)
        at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
        at emitTwo (events.js:126:13)
        at WebSocket.emit (events.js:214:7)
        at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
        at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
        at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
        at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
        at emitNone (events.js:111:20)
        at TLSSocket.emit (events.js:208:7)
        at endReadableNT (_stream_readable.js:1055:12)
        at _combinedTickCallback (internal/process/next_tick.js:138:11)
        at process._tickCallback (internal/process/next_tick.js:180:9)
    ____________________________________________
        at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
        at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
        at startWebsocket (/home/user/core/myApp.js:115:14)
        at Object.init (/home/user/core/myApp.js:212:3)
        at main (/home/user/core/core_main.js:143:16)
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:188:7)

 - What is causing the crash? 
 - Can I catch the error somewhere and react
   to it better? 
 - How can I debug this better?
 - Thank you!

UPDATE: 
user keja reminded me to add `websocket.on('error', (err) => console.log('error:', err));` to my listeners. The result is a similar but longer stack trace of the error message:

ON ERROR:
{ Error: read ECONNRESET
    at _errnoException (util.js:1022:11)
    at TLSWrap.onread (net.js:615:25)
____________________________________________
    at startWebsocket (/home/user/core/myApp.js:136:6)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitNone (events.js:111:20)
    at TLSSocket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitNone (events.js:111:20)
    at TLSSocket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitNone (events.js:111:20)
    at TLSSocket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1055:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Timeout.<anonymous> (/home/user/core/myApp.js:120:31)
    at ontimeout (timers.js:475:11)
    at tryOnTimeout (timers.js:310:5)
    at Timer.listOnTimeout (timers.js:270:5)
____________________________________________
    at WebSocket.bfx.onclose (/home/user/core/myApp.js:120:9)
    at WebSocket.onClose (/home/user/core/node_modules/ws/lib/EventTarget.js:103:16)
    at emitTwo (events.js:126:13)
    at WebSocket.emit (events.js:214:7)
    at WebSocket.emitClose (/home/user/core/node_modules/ws/lib/WebSocket.js:211:10)
    at _receiver.cleanup (/home/user/core/node_modules/ws/lib/WebSocket.js:199:39)
    at Receiver.cleanup (/home/user/core/node_modules/ws/lib/Receiver.js:520:15)
    at WebSocket.finalize (/home/user/core/node_modules/ws/lib/WebSocket.js:199:20)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
____________________________________________
    at WebSocket.addEventListener (/home/user/core/node_modules/ws/lib/EventTarget.js:121:12)
    at WebSocket.set (/home/user/core/node_modules/ws/lib/WebSocket.js:434:12)
    at startWebsocket (/home/user/core/myApp.js:118:14)
    at Object.init (/home/user/core/myApp.js:224:3)
    at main (/home/user/core/core_main.js:143:16)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

1 个答案:

答案 0 :(得分:2)

根据documentation,您可以收听错误事件

所以你可以试试像

这样的东西
websocket.on('error', (err) => console.log('error:', err));

也许这可以指出你的方向是错误的。