node-musicbrainz icon indicating copy to clipboard operation
node-musicbrainz copied to clipboard

Infinite loop

Open alefz3r0 opened this issue 4 years ago • 2 comments

I am using the module in an angular project

Musicbrainz.searchReleases('Elephant', { country: 'US' }, function(err, releases){ console.log(releases); });

The snippet above results in an infinite response loop, that returns correct results, but infinitely.

alefz3r0 avatar May 06 '20 15:05 alefz3r0

Hi. I just tried your example code and I didn't get multiple calls of the callback function. This module is very, very old and it's very possible that there are a few bad bugs.

If you're interested, and if it still happens on your computer, you could give it a shot and add some debugging outputs to mb.search() (source) to find out where the infinite loop is happening.

When I look at the source, calling lookup() in case of a 503 error immediately looks suspicious (source) but also the "end" event listener on the XML parser (source) could be fired multiple times.

I'd happily merge your pull-request if you find out what the issue is.

maxkueng avatar May 21 '20 11:05 maxkueng

Okay, I found out that the request module was calling the result callback twice (not infinitely though). I've upgraded the dependency and it's now only called once.

I've published version 0.2.7 on npm. Could you try the new version and close this issue if it fixes your problem? Thank you very much.

The following code prints 25 only once:

mb.searchReleases(
  'Elephant',
  { country: 'US' },
  function(err, releases) {
    console.log(releases.length);
  },
);

maxkueng avatar May 21 '20 12:05 maxkueng