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

SelectConnection catches all errors and hides details. #1390

Open
tango-taylor opened this issue Sep 16, 2022 · 2 comments
Open

SelectConnection catches all errors and hides details. #1390

tango-taylor opened this issue Sep 16, 2022 · 2 comments
Assignees
Milestone

Comments

@tango-taylor
Copy link

tango-taylor commented Sep 16, 2022

Originally from an SO question but I'll report it here via @lukebakken's request.

SelectConnection seems to catch all errors and doesn't provide any stack trace information. This makes debugging difficult.

For instance, here's an example where it divides by 0 in the _on_connection_open callback.

import pika

class AsyncServer():
    def __init__(self):
        self._channel = None

    def run(self):
        self._connection = self._connect()
        self._connection.ioloop.start()

    def _connect(self) -> pika.SelectConnection:
        return pika.SelectConnection(
            parameters=pika.ConnectionParameters(host='localhost'),
            on_open_callback=self._on_connection_open,
            on_close_callback=self._on_connection_closed
        )

    def _on_connection_open(self, connection):
        # Cause an error
        x = 1/0

    def _on_connection_closed(self, connection, reason):
        print("Reason for closing: ",reason)
        print("Exception class: ",reason.__class__)
        self._connection.ioloop.stop()


if __name__ == '__main__':
    recv = AsyncServer()
    recv.run()

And the output:

Reason for closing:  Stream connection lost: ZeroDivisionError('division by zero')
Exception class:  <class 'pika.exceptions.StreamLostError'>

Notice the exception is a StreamLostError instead of a ZeroDivisionError which squashes all details of the inner exception. traceback.print_exc() won't work here because the exception has already been caught.

Some possible fixes:

  • Add a flag to disable exception handling and raise them to the top like BlockingConnection does
  • Send traceback information to the callback provided by on_close_callback
@lukebakken lukebakken added this to the 2.0.0 milestone Oct 18, 2022
@lukebakken lukebakken self-assigned this Oct 18, 2022
@akselerando
Copy link

Is there a way to work around this issue? I have the same problem, which makes it difficult to find where the exception originally was raised.

@lukebakken
Copy link
Member

This issue is on my radar, but I am very busy working on the next .NET client release.

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

3 participants