Skip to content

Commit

Permalink
Fixed abort crash by waiting for all child threads to finish before e…
Browse files Browse the repository at this point in the history
…xiting spawning thread.
  • Loading branch information
kbuffington committed May 12, 2021
1 parent e122f8b commit 485d729
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ namespace mb
return json();
}
catch (exception_aborted) {
// ignore
// don't show popup
FB2K_console_formatter() << component_title << ": User aborted";
return json();
}
catch (const std::exception& e)
{
Expand Down
28 changes: 8 additions & 20 deletions src/request_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ namespace mb
}

}
//catch (exception_aborted) {
// // ignore
//}
catch (std::exception const& e) {
m_failMsg = e.what();
FB2K_console_formatter() << component_title << ": " << m_failMsg;
Expand Down Expand Up @@ -132,32 +129,23 @@ namespace mb

for (size_t i = 0; i < count; ++i)
{
/**
* this was pre-existing logic which would abort when we didn't receive anything back
* from musicbrainz. This would prevent hammering if mb is down, but also (silently!)
* fails even if we had some number of requests that already completed successfully.
* Keeping this for now, but it's subject to change later.
**/
// TOOD: This code is now worthless since all the threads are spawned before queries are
// made. We'll need to abort elsewhere if we care enough.
if (m_failed) {
FB2K_console_formatter() << component_title << ": Musicbrainz query failed.";
return;
}

// async requests
get_release_info* task = new get_release_info(ids[i], handle_count, &m_release_list, &m_failed, abort);
if (!simple_thread_pool::instance().enqueue(task)) delete task;
}
Sleep(10); // wait for last thread to start
while (m_release_list.size() < thread_counter && !abort.is_aborting()) {
size_t size = -1; // m_release_list.size can never be > 200
while (m_release_list.size() < thread_counter) {
// Is there a better way to wait for all the threads to complete?
status.set_title(PFC_string_formatter() << "Fetching release " << (m_release_list.size() + 1) << " of " << count);
status.set_progress(1 + m_release_list.size(), count);
if (m_release_list.size() != size) {
size = m_release_list.size();
status.set_title(PFC_string_formatter() << "Fetching release " << (size + 1) << " of " << count);
status.set_progress(size + 1, count);
}
Sleep(10);
}
queryingMB = false;
if (m_failed) {
if (m_failed && !abort.is_aborting()) {
FB2K_console_formatter() << component_title << ": Musicbrainz query failed.";
}
}
Expand Down

0 comments on commit 485d729

Please sign in to comment.