-
Notifications
You must be signed in to change notification settings - Fork 839
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
on_open_error_callback not called for ProbableAuthenticationError #526
Conversation
If the connection was not in CONNECTION_OPEN state yet, this indicates that the connection was never fully established and we should call the _on_open_error callbacks.
It's not possible to handle this exception anywhere and it's super noisy.
1 similar comment
Have you examined the impact that your change to BaseConnection will have on all of the connection adapters? |
super(TornadoConnection, self)._adapter_disconnect() | ||
try: | ||
super(TornadoConnection, self)._adapter_disconnect() | ||
except exceptions.AMQPConnectionError as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the exception being intentionally suppressed here? Please add a comment explaining why the exception is being suppressed and how user code might become informed of the failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vitaly-krugl , thanks for checking. The commit message had the reason:
tornado_connection: silence AMQPConnectionError in _adapter_disconnect
It's not possible to handle this exception anywhere and it's super noisy.
18de5f8
AFAICT, if a AMQPConnectionError
happens at that point inside a tornado callback, you as a user can't catch it anywhere reasonably well and it.
However - I recently came across the following messages which seem to be caused by this change (in the scenario of #525 ):
CRITICAL:pika.adapters.base_connection:Tried to handle an error where no error existed
Seems some other code is relying for the exception to happen so it's not executed... :-/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see how an exception here is a problem for frameworks like Tornado and Twisted that rely on continuation-passing style. I am not aware of an ideal solution for this in the existing pika code. Does TornadoConnection's stop_ioloop_on_close=True
cause the ioloop to stop in the #525 scenario? I see that there are other types of exceptions that would be problematic for these frameworks, such as exceptions.ProtocolVersionMismatch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For torando I think only after applying b999636 - the code of the finally
clause was skipped previously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the following might do the trick for you (in addition to suppressing AMQPConnectionError in tornado_connection.py):
-
Add try/finally in
BaseConnection._handle_disconnect()
:def _handle_disconnect(self): """Called internally when the socket is disconnected already """ try: self._adapter_disconnect() finally: self._on_connection_closed(None, True)
-
Pass
on_close_callback
in addition toon_open_error_callback
callback function to the TornadoConnection constructor.
I think this will assure that your on_close_callback
will be called if AMQP handshake fails. The on_open_error_callback
callback should be called if connection setup (TCP/IP connection or SSL handshake) fails prior to AMQP handshake.
on_open_error_callback
is defined in pika as "Method to call if the connection cant be opened", which makes it seem like it's intended to report errors in TCP/IP connection establishment; whereas on_close_callback
is intended for the AMQP handshake phase and later, since on_close_callback
may be given the reason_code
and reason_text
args that can only come from the broker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used on_open_error_callback
because at that point, the state of the connection is not in CONNECTION_OPEN
yet. Also, I think you do not get a reason/message from the broker. The connection essentially times out. That's why ProbableAuthenticationError
.
I leave this decision to @gmr .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@awelzel, the reason I proposed the try/finally BaseConnection._handle_disconnect()
fix above is that it doesn't alter the documented semantics of on_close_callback
and on_open_error_callback
, shouldn't negatively impact any other connection classes, and is also deterministic versus "If the connection is neither open, not closed, it probably was never successfully established".
CC @gmr
Not in too close detail as they all use A possibly user visible change is that for errors that happen after Further, The default implementation ( The twisted connection uses its own |
|
||
try: | ||
self._check_state_on_disconnect() | ||
except exceptions.AMQPConnectionError as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The title of the PR refers to ProbableAuthenticationError, but the exception being trapped here is more general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The title of the PR refers to ProbableAuthenticationError, but the exception being trapped here is more general.
Yes, that is true. I observed the problem only with the ProbableAuthenticationError
. IMO, however, the on_open_error_callback
should be called for any connection errors in cases where the connection has not been fully opened.
@vitaly-krugl , I have tested that PR #672 fixes the issue. This PR is no longer relevant. |
Thank you. |
Hi Gavin,
I don't have much insight into all the interactions of the code, but the following seems to do the right thing for the TornadoConnection and should not change the existing behavior (except for calling the on_open_error_callbacks).
Thoughts?
Thanks,
Arne