vesse / node-ldapauth-fork

Simple node.js module to authenticate against an LDAP server
Other
127 stars 79 forks source link

ldapauth-fork crashes node on network errors #39

Closed godmar closed 7 years ago

godmar commented 8 years ago

The LDAP server I'm using tends to, for reasons I'm not privy to, reset its connection to my node.js application.

This results in an uncaught error that causes node to exit:

Uncaught Error: read ECONNRESET

FROM
Client.emit (events.js:160:7)
Socket.onSocketError (/var/www/html/node_modules/ldapjs/lib/client/client.js:1169:12)
emitOne (events.js:96:13)
Socket.emit (events.js:188:7)
emitErrorNT (net.js:1272:8)
_combinedTickCallback (internal/process/next_tick.js:74:11)
process._tickCallback (internal/process/next_tick.js:98:9)

I am using ldapauth-fork as described in issue #38

I understand that the uncaught exception is thrown because there is no listener for the 'error' event - but the event fires on 'Client'. I'd be grateful for any advice as to how to catch this error properly (it occurs every 5-10 mins).

Currently, I am relying on pm2 to restart node.

alexhisen commented 7 years ago

Connection failures (like trying to connecting to an IP/port that's not responding) still crash node: events.js:160 throw er; // Unhandled 'error' event ^

Error: connect ETIMEDOUT 50.250.206.120:389 at Object.exports._errnoException (util.js:1026:11) at exports._exceptionWithHostPort (util.js:1049:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)

Also, specifying connectionTimeout: 5 in LdapAuth constructor options results in it apparently never timing out and just hanging there indefinitely, at least on Windows.

j-langlois commented 7 years ago

Also, specifying connectionTimeout: 5 in LdapAuth constructor options results in it apparently never timing out and just hanging there indefinitely, at least on Windows.

Same result here, a server not responding makes the authenticate method hangs indefinitely, no matter the options

flipace commented 4 years ago

I just had the same issue and after digging a bit I found that I just had to handle error events manually.

const ldap = new LdapAuth(...);
ldap.on('error', handleLdapError);
ldap.authenticate(...);

This is even mentioned in the example in the README, I just skipped over it 🤷‍♂