Skip to content

[lldb] Print a message when background tasks take a while to complete… #8617

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

Conversation

JDevlieghere
Copy link

… (llvm#82799)

When terminating the debugger, we wait for all background tasks to complete. Given that there's no way to interrupt those treads, this can take a while. When that happens, the debugger appears to hang at exit.

The above situation is unfortunately not uncommon when background downloading of dSYMs is enabled (symbols.auto-download background). Even when calling dsymForUUID with a reasonable timeout, it can take a while to complete.

This patch improves the user experience by printing a message from the driver when it takes more than one (1) second to terminate the debugger.

(cherry picked from commit 2f343fc)

…llvm#82799)

When terminating the debugger, we wait for all background tasks to
complete. Given that there's no way to interrupt those treads, this can
take a while. When that happens, the debugger appears to hang at exit.

The above situation is unfortunately not uncommon when background
downloading of dSYMs is enabled (`symbols.auto-download background`).
Even when calling dsymForUUID with a reasonable timeout, it can take a
while to complete.

This patch improves the user experience by printing a message from the
driver when it takes more than one (1) second to terminate the debugger.

(cherry picked from commit 2f343fc)
@JDevlieghere
Copy link
Author

@swift-ci test

// than 1 second.
{
std::future<void> future =
std::async(std::launch::async, []() { SBDebugger::Terminate(); });

Choose a reason for hiding this comment

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

Is there any risk on calling Terminate() on a different thread (as opposed to printing the message on another thread and terminating in the main thread?

Copy link
Author

Choose a reason for hiding this comment

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

I can't immediately think of a reason it wouldn't be safe to do, but I didn't look at every single terminator. Doing what you suggest is possible, though it would be slightly more convoluted and slightly less efficient. You'd have to spawn an async task and check periodically whether terminate has completed on the main thread. Something like:

bool terminated = false;
SBDebugger::Terminate();
terminated = true;
std::async(std::launch::async, [&terminated]() {
  for (size_t i = 0; i < 10; ++i) {
    if (terminated)
      return;
    std::this_thread::sleep_for(100ms);
   }
   fprintf(stderr, "Waiting for background tasks to complete...\n");
}

Let me know if you think that's worth the trade-off.

Choose a reason for hiding this comment

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

If you think it's safe, it's fine with me.

Copy link

@adrian-prantl adrian-prantl left a comment

Choose a reason for hiding this comment

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

Conceptually, LGTM!

@JDevlieghere JDevlieghere merged commit 181dd79 into swift/release/6.0 Apr 24, 2024
@JDevlieghere JDevlieghere deleted the jdevlieghere/cherrypick-2f343fc1574f36b3b5ff1acf63407c53dcdac331 branch April 24, 2024 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants