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

Task was destroyed but it is pending: _coro_creating_hub_and_span #2908

Open
cnicodeme opened this issue Mar 26, 2024 · 10 comments
Open

Task was destroyed but it is pending: _coro_creating_hub_and_span #2908

cnicodeme opened this issue Mar 26, 2024 · 10 comments
Labels
Integration: Asyncio Type: Bug Something isn't working

Comments

@cnicodeme
Copy link

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.34.0

Steps to Reproduce

Hey team,

I'm having a lot of "Task was destroyed but it is pending!" issues reported at Sentry.

I'm running Sanic (v23.6.0) and here's a sample of the errors:

Task was destroyed but it is pending!
task: <Task pending name='Task-532' coro=<patch_asyncio.._sentry_task_factory.._coro_creating_hub_and_span() running at /var/www/fernand/env/lib/python3.9/site-packages/sentry_sdk/integrations/asyncio.py:52> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7f7af084d2b0>()]>>

Here's a sample:
https://cyril-nicodeme.sentry.io/issues/5081979263/events/6a88812f7d1d4c269d792b5f4b010541/

(Hopefully, you can also access more details about the issue via the UUID internally).

Expected Result

Should not have a "Task was destroyed but it is pending!" issue but properly send any issues

Actual Result

Fails with "Task was destroyed but it is pending"

@sentrivana
Copy link
Contributor

Hey @cnicodeme, thank you for reporting this!

Are the errors thrown when something specific happens (worker restarting, app shutdown, etc.) or just at random?

@cnicodeme
Copy link
Author

Yes! When I restart the app, I get a ton of these

@sentrivana
Copy link
Contributor

Thanks for confirming, I expected as much. The SDK being responsible for the errors being created is one thing, but we're even reporting them to Sentry, which is doubly wrong.

If you want to get rid of them before we fix this, one workaround would be to filter them out in a custom before_send (see docs).

@cnicodeme
Copy link
Author

Thank you!

I can implement a before_send filter, but what should I filter?

@sentrivana
Copy link
Contributor

sentrivana commented Mar 28, 2024

You could do something like this:

def my_before_send(event, hint):
    if "_coro_creating_hub_and_span()" in event["message"]:
        return None  # this event will be dropped

    return event  # send everything else


sentry_sdk.init(
    # your usual stuff
    before_send=my_before_send,
)

To see what you can filter on, you can click on the {} button on the event page in Sentry to see the raw JSON and the fields that you can use.

@cnicodeme
Copy link
Author

Thank you! Will do that!

Can you tell me which version of Sentry SDK will have the fix incorporated? So that I can remove my fix once it's resolved?

Thanks!

@sentrivana
Copy link
Contributor

No target release yet, but I'll try to remember to come back to update this issue once I know. In general, as soon as an issue gets closed, the fix is scheduled for the upcoming release, which usually takes at most a couple weeks from then.

@cnicodeme
Copy link
Author

Thank you :)

@cnicodeme
Copy link
Author

Hi,

I'm re-opening this ticket because I realized a few things:

  1. The current version of Sentry (v1.45.0) still sends the above error
  2. Implementing the if "_coro_creating_hub_and_span()" in event["message"]: code suggestion caused all errors to stop being reported at Sentry.

I've removed the before_send=my_before_send line for now, but if you could let me know on what to do to avoid these, it would be nice :)

Thanks!

@sentrivana
Copy link
Contributor

Hey @cnicodeme, this is still open, no fix for it yet. The before_send workaround should still work though -- unless there's an error in it, which might explain you not getting anything. The only thing I see that might be problematic is that message might not be there, if that's the case this should work:

def my_before_send(event, hint):
    if "_coro_creating_hub_and_span()" in (event.get("message") or ""):
        return None  # this event will be dropped

    return event  # send everything else

If it still doesn't work, please try initializing the SDK with debug=True in the init, it should tell you more about what's going wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Integration: Asyncio Type: Bug Something isn't working
Projects
Status: No status
Development

No branches or pull requests

3 participants