Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashing in Safari (LB-23) #43

Merged
merged 2 commits into from Sep 29, 2015

Conversation

mwiencek
Copy link
Member

The importer crashed every single time when I tested it in Safari 8.08, so I was able to reproduce this really easily.

With the changes here, it didn't crash at all after 8 or 9 trials.

This is clearly a bug in Safari, since there's nothing invalid about the code in question. Luckily, the code doesn't actually do anything, so we can just remove it.

Why the code does nothing:

enqueueReport pushes a single item onto toReport, then calls dispatch(), which passes that single item to reportScrobbles and immediately clears toReport.

So, there is never more than one item in toReport, and the code is equivalent to just calling reportScrobbles on the item directly.

If there used to be a purpose to that and you'd rather fix it than remove it, let me know and I'll try to fix it instead. :)

@mwiencek
Copy link
Member Author

This doesn't affect memory usage from what I can see, I just had to fix this first to even look at that in Safari. After actually checking, Firefox is the only browser that uses an insane amount of memory for me (and doesn't release it).

@alastair
Copy link
Collaborator

this is interesting. It was originally like you had it: e53aa5c
I believe it was changed to the enqueue format in an attempt to get a processing queue, except since we use async xhr, the dispatch method always runs really quickly.

I lowered the number of current queries by using activeSubmissions instead, but I still like the idea of having a list of perhaps 10 xmlhttpreq objects, which process, finished, get popped off, and then replaced with a new object with new payload. Does this make sense, or does the current system work well enough?

@mwiencek
Copy link
Member Author

Hm, well, JavaScript's event loop already acts as a queue, so I'm not sure I understand what the processing queue would do on top of that. activeSubmissions should do what you're saying, by limiting the number of concurrent submissions to 10.

I noticed there are some bugs in the way it handles activeSubmissions, though, since it regularly gets incremented beyond 10. Because it gets incremented asynchronously, inside the setTimeout, more than 10 submissions have a chance to make it past the condition. I'll push a commit to fix that too.

page += 1;
setTimeout(function() { getLastFMPage(page, reportPageAndGetNext) }, 0 + Math.random()*100);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setTimeout isn't needed because the XHR request is already asynchronous.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also what was causing more than 10 activeSubmissions at a time, since the code was incrementing activeSubmissions inside the setTimeout.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was here because originally we didn't have a limit on the number of active submission. This was a random pause between paging between last.fm pages. I wasn't really worried about having 11 or 12 activeSubmissions going, just as long as it was about 10 instead of about 100

This commit fixes the `activeSubmissions` counter, so that it no longer allows
more than 10 concurrent pages to be processed at a time, adds error handling to
the last.fm page requests, and introduces a few invariants:

    * `getNextPagesIfSlots` is the only function that increments `page` and
      `activeSubmissions`.

    * `pageDone` is the only function that decrements `activeSubmissions` and
      increments `numCompleted`.

    * Page requests/submissions will be retried until they either complete or
      are skipped (due to e.g. a 40x status code), at which point `pageDone` is
      called.
@alastair alastair merged commit 8769a2b into metabrainz:master Sep 29, 2015
@alastair
Copy link
Collaborator

This looks good, merged. thanks!

paramsingh pushed a commit that referenced this pull request Jan 19, 2020
HDFS utilities for modules and scripts
paramsingh pushed a commit that referenced this pull request Apr 23, 2020
Add pull request template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants