node-ldapjs
node-ldapjs copied to clipboard
Client Search keeps in loading for to many users
Hi, I'm trying to get users for an ldap account that has lots of members, trying to make a search but it keeps loading and never get a response:
const client = ldap.createClient({
url: 'ldap://XX.XXX.XX.XXX:XXX/',
})
client.bind(`${username}`, ${password}, (err) => {
if (!err) {
const base = 'ou=osup01,ou=xrep01,DC=XXXXXX,DC=LOCAL'
const options = {
sizeLimit: 100,
paged: true,
scope: 'sub' as 'sub',
filter:
'(&(objectCategory=person)(objectClass=user))',
attributes: [
'givenName',
'whenCreated',
'displayName',
'memberOf',
'lastLogonTimestamp',
'mail',
],
}
client.search(base, options, function(err, res) {
res.on('searchEntry', function(entry) {
console.log('entry: ' + JSON.stringify(entry.object))
})
res.on('searchReference', function(referral) {
console.log('referral: ' + referral.uris.join())
})
res.on('error', function(err) {
console.error('error: ' + err.message)
})
res.on('end', function(result) {
console.log('status: ' + result!.status)
})
})
In console, it printed some of the members in the line: console.log('entry: ' + JSON.stringify(entry.object)) but then it stucks
Making the request by linux command it gives me the next numbers of responses:
- numResponses: 1490
- numEntries: 1486
- numReferences: 3
how could I manage a large number of members and get all in the response? could you help please?
Thanks!
I do not believe there is enough context in your example. Are you executing this within some other context that will end the connection? According to the docs (https://github.com/ldapjs/node-ldapjs/blob/b83008c71792c4e01fe2e69485987ca7c5e93e3c/docs/client.md#search) your code as written is correct. Without a reproducible example, I cannot say more.
Hello, may I suggest, to read the docs again.
I is my unterstanding, that - as called with your option - the lib does the paging for you in the background (asks 100 entries, emits them through the searchEntry event.)
If you want more control, then you can make the paged option to an object, and can declare a pagesize, and an option pagePause: true.
If you look at the docs here, you will find this example, with the page event
var queue = new MyWorkQueue(someSlowWorkFunction);
var opts = {
filter: '(objectclass=commonobject)',
scope: 'sub',
paged: {
pageSize: 250,
pagePause: true
},
};
client.search('o=largerdir', opts, function(err, res) {
assert.ifError(err);
res.on('searchEntry', function(entry) {
// Submit incoming objects to queue
queue.push(entry);
});
res.on('page', function(result, cb) {
// Allow the queue to flush before fetching next page
queue.cbWhenFlushed(cb);
});
res.on('error', function(resErr) {
assert.ifError(resErr);
});
res.on('end', function(result) {
console.log('done');
});
});
I have tried this and it didn't work for me. I still just get 250 results followed by. a 'page' event with a cb. Calling the cb gets me nothing. I even tried adding a synchronous wait (1000ms) before calling the page cb - still nothing.
👋
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.