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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client stops trying to connect if disconnected_cb raises exception #204

Open
mprimi opened this issue Aug 6, 2021 · 2 comments
Open

Client stops trying to connect if disconnected_cb raises exception #204

mprimi opened this issue Aug 6, 2021 · 2 comments

Comments

@mprimi
Copy link

mprimi commented Aug 6, 2021

If the callback passed to disconnected_cb raises an exception, then the NATS client will never reconnect to the cluster.

While this behavior could be classified as "user error" (that callback should not throw!), it would be nice to handle this gracefully:

  • Print an error message so the user knows the callback has raised an exception (currently no message)
  • Keep trying to reconnect (currently, no attempt to reconnect)

Attaching a simple script that reproduces the behavior: callback_exception.py.txt

See instructions at the top of the file.

Expected behavior:

📤 Message published
📥 Message received
📤 Message published
📥 Message received
📤 Message published
📥 Message received
>>>> Server crash-restart
nats: encountered error
NoneType: None
🔴 Disconnected!
🟢 Reconnected!
📤 Message published
📥 Message received
📤 Message published
📥 Message received

Actual behavior (with DISCONNECT_CALLBACK_EXCEPTION=True):

📤 Message published
📥 Message received
📤 Message published
📥 Message received
📤 Message published
📥 Message received
>>>> Server crash-restart
nats: encountered error
NoneType: None
🔴 Disconnected!
📤 Message published
📤 Message published
📤 Message published
📤 Message published

Notice no errors, no attempts to reconnect, and no message delivered forever after

@mprimi
Copy link
Author

mprimi commented Aug 6, 2021

Possible solution discussed in Slack: wrap all callbacks so they can't do any damage if they raise exceptions

@theobouwman
Copy link

Would this potentially solve airtai/faststream#1581 (comment) ?

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

No branches or pull requests

2 participants