node-ldapjs
node-ldapjs copied to clipboard
Unhandled error event
This is the error I'm seeing when trying to look up a user:
2016-03-11T15:08:57.94+0100 [App/0] ERR events.js:141 2016-03-11T15:08:57.94+0100 [App/0] ERR throw er; // Unhandled 'error' event 2016-03-11T15:08:57.94+0100 [App/0] ERR ^ 2016-03-11T15:08:57.94+0100 [App/0] ERR Error: getaddrinfo ENOTFOUND company.com:636 2016-03-11T15:08:57.94+0100 [App/0] ERR at errnoException (dns.js:26:10) 2016-03-11T15:08:57.94+0100 [App/0] ERR at GetAddrInfoReqWrap.onlookup as oncomplete
using node v4.4.0, ldapjs 1.0.0.
I suspect that the ldap server is not accessible, but this shouldn't result in an unhandled error event, should it? Thanks
I do not think it is an good idea, but you could use empty handler for ignore errors as workaround:
var client = ldap.createClient(opts);
client.on('error', function(){});
Or handle any other errors here and ignore only ENOTFOUND.
This bug still persists in 2018 (version 1.0.2)
What happened with #433 bugfix ?
I think this problem should be considered as a documentation bug, since the outlined examples on http://ldapjs.org/client.html do not explain how to securely setup a ldap connection...
// Define LDAP client connection setting
var ldap_client_object = {
url: 'ldap://192.168.0.1:389/',
connectTimeout: 2000,
timeout: 5000,
};
// Create LDAP client connection
var ldap_client = ldap.createClient( ldap_client_object );
// Register a LDAP client connection "error" handler
ldap_client.on( 'error', function( err ) {
// The LDAP client connection has generated an error...
});
// Register a LDAP client connection "connectTimeout" handler
ldap_client.on( 'connectTimeout', function( err ) {
// The ldap connection attempt has been timed out...
});
// Register a LDAP client connection "connect" handler
ldap_client.on( 'connect', function( ) {
// The ldap connection is ready to use. Place your subsequent ldapjs code here...
});
HTH and Cheers, Kai
I think @KaiWilke is right, this looks like a documentation issue. The library has pretty poor documentation and I believe a lot of this is from the author expecting users to already have a good understanding / experience working with LDAP.
Unfortunately looks at the lack of attention from the maintainer and open PRs I don't see it worth updating the docs, because they will likely never get merged.
It sounds like you are missing a client.on('error', handler)
. I do believe this could be better described in the documentation. A PR would be very welcome.
👋
On February 22, 2023, we released version 3 of this library. As a result, we are closing this issue/pull request.
Please see issue #839 for more information, including how to proceed if you feel this closure is in error.