Skip to content

Sentry hangs multiprocessing application with mp.Manager resources #2197

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

Closed
rafalpotempa opened this issue Jun 26, 2023 · 3 comments
Closed

Comments

@rafalpotempa
Copy link

How do you use Sentry?

Sentry Saas (sentry.io)

Version

1.25.1

Steps to Reproduce

While using Python sentry_sdk version 1.25.1 together with multiprocessing.Manager that has some shared values, the process hangs after receiving an exception in subprocess.

The problem occurs only when manager.Value and Sentry are initialized at the same time. Commenting out any of them releases the execution. You can see that the values doesn't have to be used by subprocess. The multiprocessing creates a process called resource tracked which might be conflicting with closing the Sentry watcher correctly.

You can recreate the issue using the snippet below.

  • SENTRY_DSN env variable is set to proper value
  • produced on MacOS, so "spawn" context is used by default
import multiprocessing
import os
import sentry_sdk
import time


def _check_workers(workers):
    if any([worker.exitcode != 0 for worker in workers]):
        raise Exception("Hanging with this error")


def wait_for_processes(workers, sleep_seconds=5):
    while any([worker.is_alive() for worker in workers]):
        _check_workers(workers=workers)

        time.sleep(sleep_seconds)

    _check_workers(workers=workers)


def failing_function():
    raise ValueError("Test error")


def execute():
    manager = multiprocessing.Manager()
    this_hangs = manager.Value("i", 10)  # presence of this resource hangs the process

    worker = multiprocessing.Process(
        target=failing_function,
    )
    worker.start()

    wait_for_processes([worker])


if __name__ == "__main__":
    sentry_sdk.init(dsn=os.environ.get("SENTRY_DSN"))
    execute()

Expected Result

Sentry handles the exception received in the main process, reraises it and the program execution ends with non-zero exit code.

Actual Result

The program receives the exception but waits infinitely for something to end it.

@antonpirker
Copy link
Member

Related: #291

@antonpirker
Copy link
Member

Hey @rafalpotempa !

Better late than never. I just tried to reproduce this. I ran your sample code with SDK version 1.35.0 and Python 3.9.15 and the programm finishes and the error "Hanging with this error" shows up in Sentry. (the error "Test error" from the worker is not showing up in Sentry because it is run in another process that has no Sentry in it. (Sentry is not yet able to capture those errors in subprocesses)).

Can you retry with and updated version of the Sentry SDK and tell me if this is still an issue you are having? Thanks!

@getsantry getsantry bot moved this from Waiting for: Product Owner to Waiting for: Community in GitHub Issues with 👀 Nov 20, 2023
@getsantry
Copy link

getsantry bot commented Dec 12, 2023

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added the Stale label Dec 12, 2023
@getsantry getsantry bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

5 participants