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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not log the exception before attempting an non-blocking dial #114

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

olivierpelet
Copy link

When the block argument is not specified or is set to None during a call to dial(), the library tries to do a blocking connection first.
If a pynng.ConnectionRefused occurs, the exception is logged using the global logger and then a non-blocking connection is attempted.

In my opinion the exception should not be logged (especially using the global logger).
I've spent 2 hours figuring out that the exception displayed in my terminal does not occur in my code and is "normal" because I did not specified the block argument 馃榾

Here a small code example:

from pynng import Req0, NNGException

try:
    with Req0(dial="tcp://127.0.0.1:9093") as sock:
        sock.send_timeout = 3000
        sock.recv_timeout = 3000
        sock.send(b"my_data")
except NNGException as err:
    print(f"Exception occured in my code: {err}")

The output without this patch:

Synchronous dial failed; attempting asynchronous now
Traceback (most recent call last):
  File "/home/olivier/dev/tests/pynng-fix/pynng-master/pynng/nng.py", line 374, in dial
    return self.dial(address, block=True)
  File "/home/olivier/dev/tests/pynng-fix/pynng-master/pynng/nng.py", line 371, in dial
    return self._dial(address, flags=0)
  File "/home/olivier/dev/tests/pynng-fix/pynng-master/pynng/nng.py", line 390, in _dial
    check_err(ret)
  File "/home/olivier/dev/tests/pynng-fix/pynng-master/pynng/exceptions.py", line 201, in check_err
    raise exc(string, err)
pynng.exceptions.ConnectionRefused: Connection refused
Exception occured in my code: Timed out

The output with this patch:

Exception occured in my code: Timed out

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

Successfully merging this pull request may close these issues.

None yet

1 participant