yBrodsky
yBrodsky

Reputation: 5041

Node imap - unstable internet connection and socket error

I have implemented node imap (https://github.com/mscdex/node-imap). Listening for emails in an opened inbox. Works fine and without any problem. However, while working with a very unstable internet connection, it seems that the connection is lost and some error appears:

Error: This socket is closed
    at Socket._writeGeneric (net.js:733:18)
    at Socket._write (net.js:787:8)
    at doWrite (_stream_writable.js:396:12)
    at clearBuffer (_stream_writable.js:523:7)
    at Socket.Writable.uncork (_stream_writable.js:312:7)
    at JSStreamWrap.doWrite (internal/wrap_js_stream.js:119:17)
    at JSStreamWrap.handle.onwrite (internal/wrap_js_stream.js:37:42)
    at shutdownSocket (net.js:286:23)
    at defaultTriggerAsyncIdScope (internal/async_hooks.js:281:19)
    at TLSSocket.Socket._final (net.js:312:13)
    at callFinal (_stream_writable.js:584:10)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickDomainCallback (internal/process/next_tick.js:219:9)

I have handlers for all the relevants events as far as I know

  imap.once('error', function(err) {

  });

  imap.once('close', function(err) {

  });

  imap.once('end', function(err) {

  });

However the error is not falling into any of those. Furthermore, I have everything wrapped inside a try/catch, still the error crashes the node process and I have to restart it.

Any idea how to go around this? Ideally catch the error and give it a chance to end/restart the imap connection.

Upvotes: 0

Views: 565

Answers (0)

Related Questions