aws / aws/aws-greengrass-core-sdk-python
StreamManager client leaks threads during init
- Dominant language
- Python
- Stars
- 55
- Forks
- 39
- PR merge metrics
- No merged PRs in 30d
Description
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](https://github.com/aws/aws-greengrass-core-sdk-python/blob/master/greengrasssdk/stream_manager/streammanagerclient.py#L110-L111) 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.
Contributor guide
Assessment
This issue has not been assessed yet.