
# Issue

So far, there were two reasons for occurrences of this bug:

*   due to `os.fork`-ed client which hangs on `import` inside `requests` library

*   due to a deadlock of writing `stdout` by child and reading that by parent

# Status

*   Hang on `import` is not fixed, but alleviated with a timer which tells when import hands.

    This tells about issue immediately, and user can retry
    rather than waiting and guessing why response takes long time.

*   Hang on write to `stdout` might be fixed.

    The root cause may likely be due to a deadlock when:
    *   parent looped on child existence without reading pipe
    *   child was blocked on pipe write

# Workaround

If spinner is disabled (see [`show_pending_spinner`](https://github.com/argrelay/argrelay/blob/v0.7.0.final/src/argrelay/sample_conf/argrelay.client.json#L8)),
it does not happen (because another client process is not `os.fork`-ed).

# Identification

When spinner hangs infinitely, press `Ctrl+C` -
it prints (interleaved) stack traces for both child and parent to identify if it is the same issue.

After filtering out interleaved lines,
stack trace from hanged [`argrelay` client version 0.7.0.final](https://github.com/argrelay/argrelay/blob/v0.7.0.final/src/argrelay/relay_client/__main__.py#L84)
using [`requests` version 2.31.0](https://github.com/psf/requests/blob/v2.31.0/requests/__init__.py#L160):
```
File "/venv/lib/python3. 11/site-packages/argrelay/relay_client/__main__.py", line 84, in main
from argrelay.relay_client.RemoteClient import RemoteClient
File "/venv/lib/python3.11/site-packages/argrelay/relay_client/RemoteClient.py”, line 2, in <module>
from argrelay.relay_client.RemoteClientCommandFactory import RemoteClientCommandFactory
File "/venv/lib/python3.11/site-packages/argrelay/relay_client/RemoteClientCommandFactory. py”, line 1, in <module>
from argrelay.client_command_remote. AbstractRemoteClientCommand import AbstractRemoteClientCommand
File "/venv/lib/python3.11/site-packages/argrelay/client_command_remote/AbstractRemoteClientCommand.py", line 4, in <module>
import requests
File "/venv/lib/python3.11/site-packages/requests/__init_.py", line 160, in <module>
from .api import delete, get, head, options, patch, post, put, request
File "/venv/lib/python3.11/site-packages/requests/api.py”, line 11, in <module>
from . import sessions
File "/venv/lib/python3.11/site-packages/requests/sessions.py”, line 15, in <module>
from .adapters import HTTPAdapter
File "/venv/lib/python3.11/site-packages/requests/adapters.py”, line 44, in <module>
from .models import Response
File "/venv/lib/python3.11/site-packages/requests/models. py”, line 13, in <module>
import encodings.idna  # noqa: F401
File "<frozen importlib._bootstrap>", line 224, in _lock_unlock_module
File “<frozen importlib._bootstrap>", line 120, in acquire
KeyboardInterrupt
```

# Addressing the issue

*   The initial attempt was detection of the issue - setting 1-sec-alarm before the `import`.

    It worked - instead of infinite spinning, child simply exited after printing error message.

*   The next step was to remove `exit` assuming the `import` would simply complete after `SIGALRM` handler.
