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

StreamManager client leaks threads during init #18

Open
AndreyShprengel opened this issue Oct 6, 2024 · 0 comments
Open

StreamManager client leaks threads during init #18

AndreyShprengel opened this issue Oct 6, 2024 · 0 comments

Comments

@AndreyShprengel
Copy link

If an exception occurs during the __init__ of the stream manager client (for example a bad port is passed or the server is temporarily down) the event loop thread gets leaked. Because the init never returns there is no client object to call close() on.

This can be reproduced with a simple script (assuming the server is not listening on port 1234)

import threading
from greengrasssdk.stream_manager import StreamManagerClient
while True:
    threads = threading.enumerate()
    print(f"Number of threads: {len(threads)}")
    try:
        client = StreamManagerClient(port=1234)
    except Exception as e:
        print(f"Exception: {e}")

which produces the following output:

Number of threads: 1
Connection error while connecting to server: [Errno 111] Connect call failed ('127.0.0.1', 1234)
Exception: [Errno 111] Connect call failed ('127.0.0.1', 1234)
Number of threads: 2
Connection error while connecting to server: [Errno 111] Connect call failed ('127.0.0.1', 1234)
Exception: [Errno 111] Connect call failed ('127.0.0.1', 1234)
Number of threads: 3
Connection error while connecting to server: [Errno 111] Connect call failed ('127.0.0.1', 1234)
Exception: [Errno 111] Connect call failed ('127.0.0.1', 1234)
...
Number of threads: 507
Connection error while connecting to server: [Errno 111] Connect call failed ('127.0.0.1', 1234)
Exception: [Errno 111] Connect call failed ('127.0.0.1', 1234)
Number of threads: 508
Exception: can't start new thread
Number of threads: 508
Exception: can't start new thread
Number of threads: 508
Exception: can't start new thread

This leads to the developer needing to manually find and kill the event loop thread.

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

No branches or pull requests

1 participant