question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Search entries emitted too soon

See original GitHub issue

When using the client.search() API, I encountered an issue, where my client sometimes missed the first few searchEntry events (or even the end event). Apparently, if the LDAP server is much faster than the client, the client does not have enough time to bind event listeners in the callback.

In order to mitigate this issue, I published the fork ldapjs-with-injectable-emitter, which, in it’s search options, accepts an optional EventEmitter instance, so that the user can set up all bindings before actually firing off the request. It can be used as follows:

return new Promise((resolve, reject) => {
  const entries = []

  const emitter = new EventEmitter()
  emitter.on('searchEntry', entry => { users.push(entry) })
  emitter.on('error', err => reject(err))
  emitter.on('end', () => resolve(entries))

  client.search('ou=People', { emitter }, (err, res) => {
    if (err) reject(err)

    // Calling res.on(...) here might be too late
    res === emitter // => true
  })
})

This fixes my use-case, but the issue still remains for users of v1.0.2. Therefore I’d like to open discussion regarding to either implement this approach in ldapjs or come up with another solution, so that ldapjs users can mitigate this caveat.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
rkaw92commented, May 12, 2020

Hi, I’ve just authored a patch (linked above) against next that addresses this without any API changes, by using a custom EventEmitter that stores unemitted events and only emits them when a listener is added. This is necessary because, while it seems like the original API was meant to emulate that of Node.js Streams, it failed to do so reliably because it lacked a “cork” / “flowing mode” distinction that actual Streams have.

Streams do internal buffering and only start emitting entries when a listener for data is added - this is properly called switching into “flowing mode”, where new data is emitted as it arrives. This is what we eventually want, but only after ensuring that the programmer has had a chance to register event listeners.

Thanks to the test by @ifroz, I had good assertions ready to verify against.

Please let me know what you think. We’ll also get around soon to testing this manually on a specific host where an issue with missing search results (supposedly this) is known to occur predictably.

Also, I’ve had some issues running the tests locally where 2 tests would fail on next right after cloning from the upstream and doing an npm install, on Node 12.16.1 - my patch doesn’t seem to introduce any additional failures, however, and running the newly-added tests in isolation with --only yields success. Any assistance here would be appreciated - shall I paste the test failures I’m having, or can somebody else try the upstream next branch and check if they concur?

1reaction
UziTechcommented, May 12, 2020

Great work @rkaw92! If you could create a PR against the next branch with that commit the GitHub CI could run the tests and we could see any issues there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Every Google search results in CO2 emissions. This real-time ...
Every Google search results in CO2 emissions. This real-time data viz shows how much. “The internet is not a cloud.”.
Read more >
Google Algorithm Updates & Changes: A Complete History
Learn about the biggest and most important Google search algorithm launches, updates, and refreshes of all time – from 2003 to today.
Read more >
Ranking Results – How Google Search Works
Information such as your location, past Search history, and Search settings all help us to ensure your results are what is most useful...
Read more >
Google execs warn of reputational risk with ChatGBT-like tool
Google execs warn company's reputation could suffer if it moves too fast on AI-chat technology. Published Tue, Dec 13 20225:28 PM EST.
Read more >
Google accused of airbrushing carbon emissions in flight ...
Google has been accused of airbrushing aviation emissions, after the company changed its flight search engine to halve the CO 2 emissions ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found