Skip to content

Eventlet might cause FD leak #4829

@hscspring

Description

@hscspring

How do you use Sentry?

Self-hosted/on-premise

Version

2.38.0

Steps to Reproduce

pip install dnspython==2.3.0

import os, sys
import threading
import subprocess

import sentry_sdk
import urllib3


def send_log():
    try:
        urllib3.request("GET", "127.0.0.1")
    except Exception as e:
        pass


def show_fds():
    pid = os.getpid()
    cmd = f"lsof -p {pid} | awk '{{print $5}}' | sort | uniq -c | sort -nr"
    out = subprocess.check_output(cmd, shell=True)
    print(out.decode())


if __name__ == "__main__":
    print("Init FD:")
    show_fds()

    threads = [threading.Thread(target=send_log) for _ in range(10)]
    for t in threads:
        t.start()
    for t in threads:
        t.join()

    # time.sleep(1)
    print("\nNew FD:")
    show_fds()

Expected Result

1 a_inode

# sentry_sdk/utils.py

from eventlet.patcher import is_monkey_patched

All comes from this line of code. when you did this, eventlet has already patched, as below:

sentry_sdk -> eventlet -> greendns -> dns -> dns.query -> requests -> urllib3

here dnspython==2.3.0 is neccessary, it will try to import requests, and cause the side effect.

If we upgrade dnspython, then everything is well~

I think it's an interesting issue, so record it here.

Actual Result

11 a_inode

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions