emailjs / emailjs-imap-client

Low-level JS IMAP client for all your IMAP needs.
MIT License
552 stars 123 forks source link

Added timeouts to ensure timely errors when a connection drops #261

Closed gudmundurg74 closed 2 years ago

gudmundurg74 commented 2 years ago

We've been seeing clients hang in rare cases when a connection drops, in the sense that request promises are not fulfilled leaving our code hanging. The cases fixed here are hard to pinpoint because there's no logging to help, I managed to produce these cases here semi-reliably and debug them.

So there seems to be a gap in when we have the error timeouts set, and that gap is basically between incoming IMAP commands.

So I've added a couple of timeout resets to _handleResponse for when all these conditions are met:

  1. A command is finished (and the socket timeout cleared in _iterateIncomingBuffer).
  2. _currentCommand still exists.
  3. a response to _currentCommand is not yet ready for a callback.

This seems to have fixed the client hangs I was able to produce - the result is that in those cases the timeout would fire and the client would error out, rejecting the request promise.

NetHans commented 1 year ago

would it be possible to update the NPM package to use this customization via the standard NPM process?