Skip to content

[Bug] Unhandled exceptions emerging from orphan threads on server #139

Open
@3manifold

Description

@3manifold

Description

As soon as the server starts, the main thread runs and exits immediately (main call) leaving the child threads (handlers) running in an orphan state.

This can have several consequences, including resource leakage (orphan threads may continue to consume system resources, leading to potential performance degradation) and unpredictable behavior (the behavior of orphan threads can be unpredictable since they are no longer under the control of their parent). In specific, one of the issues can be unhandled thread exceptions, as demonstrated in the section that follows.

Reproduce

Run locally:

  1. python3 s2s_pipeline.py --recv_host 0.0.0.0 --send_host 0.0.0.0 # wait for server to start..
  2. python3 listen_and_play.py
  3. kill -2 <server_PID> # send KeyboardInterrupt to server
  4. # Press Enter in client session to terminate client
  5. # Exception message is shown in the server session

The script above will cause the following error:

....
... - connections.socket_sender - INFO - Sender waiting to be connected...
... - connections.socket_receiver - INFO - receiver connected
... - connections.socket_sender - INFO - sender connected
Exception ignored in: <module 'threading' from '/usr/lib/python3.10/threading.py'>
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1567, in _shutdown
    lock.acquire()
KeyboardInterrupt: 

Implementation as well as a description of the fix can be found in pull request #138 .

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