Skip to content

StreamManager client leaks threads during init  #18

@AndreyShprengel

Description

@AndreyShprengel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions