emailjs / emailjs-imap-client

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

Crash for connections opened for long time #121

Open nkman opened 7 years ago

nkman commented 7 years ago

For connections made for long time, FETCHing (or doing any send operation) causes the crash. The logs written below.

[DEBUG][2017-01-11T10:29:43.439Z][2] Fetching messages 2206237293 from INBOX ...
/home/ec2-user/genoa/node_modules/emailjs-imap-client/src/emailjs-imap-client-imap.js:306
            this.socket.send(buffer);
                       ^

TypeError: Cannot read property 'send' of null
    at Imap.send (/home/ec2-user/genoa/node_modules/emailjs-imap-client/src/emailjs-imap-client-imap.js:306:24)
    at Client.breakIdle (/home/ec2-user/genoa/node_modules/emailjs-imap-client/src/emailjs-imap-client.js:841:25)
    at Client.exec (/home/ec2-user/genoa/node_modules/emailjs-imap-client/src/emailjs-imap-client.js:777:21)
    at Client.listMessages (/home/ec2-user/genoa/node_modules/emailjs-imap-client/src/emailjs-imap-client.js:415:21)
    at Socket.<anonymous> (/home/ec2-user/genoa/index.js:366:60)
    at emitTwo (events.js:106:13)
    at Socket.emit (events.js:191:7)
    at /home/ec2-user/genoa/node_modules/socket.io/lib/socket.js:503:12
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
worker existed  0 1 null
restarting the worker  0
rickhall commented 7 years ago

This seems like a reasonably straightforward issue, is there a reason it hasn't been addressed?

[Edited comment, since I read the issue date incorrectly. Sorry.]

nifgraup commented 7 years ago

@rickhall the fix is marked as temp, what would a more permanent solution look like? Why is this.socket null?

rickhall commented 7 years ago

Good question. I noticed it in a similar situation where the connection was open for a while. I assumed it was some sort of connection reset or timeout, but I didn't see any such error being logged. It is not something I can easily recreate.

rickhall commented 7 years ago

Not that this will be too helpful, but it just happened to me again after leaving the connection open for a long time. I get an empty error from the logger error() and the connection onerror() callbacks. However, the error seems to be a symptom of attempting to invoke send() on a null socket, since the error is printed after the stack trace in Chrome and there is no socket error before that.

Is it possible that the socket has an error and tearDown() gets called and sets socket to null without reporting anything? The code includes:

this.socket.onclose = this.socket.onerror = tearDown; // we don't really care about the error here

rickhall commented 7 years ago

Yeah, my last comment probably doesn't make any sense, since the tearDown assignment only happens when closing the connection.

So, I'm back to "I don't know". :-)

acemtp commented 4 years ago

Any news?

We scan thousands of imap all the time and we regularly has this error (a few times per day).

We applied the "temp fix" , thanks @nkman, but it would be nice to be handled by the lib directly