DataDog / datadogpy

The Datadog Python library
https://datadoghq.com/
Other
611 stars 302 forks source link

Possible bug with dogstatsd deadlock #834

Open mazad01 opened 3 months ago

mazad01 commented 3 months ago

Describe the bug Code is hanging on datadog's post_fork() function. Possibly https://github.com/DataDog/datadogpy/blob/master/datadog/dogstatsd/base.py#L976 ?

Expected behavior Dogstatsd lib references not deadlocking

Environment and Versions (please complete the following information): dogstatsd 0.49.1

Additional context From our developers: the parent code is trying to spawn subprocesses, but it ultimately hangs

i.e snip of the code:

 process = subprocess.Popen(
        cmd,
        stdout=subprocess.PIPE,
        stderr=subprocess.STDOUT,
        shell=True,
        text=True,
        preexec_fn=_set_pdeathsig(
            signal.SIGTERM
        ),  # ensure terminate subproc if this proc dies
    )

def _set_pdeathsig(sig=signal.SIGTERM):
    """Return a callable that terminates the subprocess."""
    libc = ctypes.CDLL("libc.so.6")

    def callable():
        return libc.prctl(1, sig)

    return callable

Output of pyspy:

Thread 1733153 (idle): "Thread-52 (process_items)"
    close_socket (datadog/dogstatsd/base.py:933)
    post_fork (datadog/dogstatsd/base.py:1369)
    post_fork (datadog/dogstatsd/base.py:120)
    _execute_child (subprocess.py:1796)
    __init__ (subprocess.py:971)
...

Output of strace

strace: Process 1733153 attached
futex(0x5644f988f040, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY
vickenty commented 3 months ago

Thank you for reporting the issue.

While we are working on a fix. In the meantime, you can work around the issue by disabling fork support by setting the DD_DOGSTATSD_DISABLE_FORK_SUPPORT environment variable before importing the datadog package.

github-actions[bot] commented 2 months ago

Thanks for your contribution!

This issue has been automatically marked as stale because it has not had activity in the last 30 days. Note that the issue will not be automatically closed, but this notification will remind us to investigate why there's been inactivity. Thank you for participating in the Datadog open source community.

If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of this project.

  2. Comment that the issue is still reproducible and include updated details requested in the issue template.

mazad01 commented 2 months ago

Not stale, still waiting for resolution. Thanks

anupamdialpad commented 2 months ago

What are the side effects of setting DD_DOGSTATSD_DISABLE_FORK_SUPPORT?