Skip to content

Potentially broken _AbstractTransport.__repr__ #361

Closed
@blueyed

Description

@blueyed

_AbstractTransport.__repr__ (or Connection.__repr__) might crash.

In a report/issue from/in Sentry self was reported as "broken repr" in

self._write(s)
.

_AbstractTransport.__repr__:

py-amqp/amqp/transport.py

Lines 100 to 106 in 7300741

def __repr__(self):
if self.sock:
src = f'{self.sock.getsockname()[0]}:{self.sock.getsockname()[1]}'
dst = f'{self.sock.getpeername()[0]}:{self.sock.getpeername()[1]}'
return f'<{type(self).__name__}: {src} -> {dst} at {id(self):#x}>'
else:
return f'<{type(self).__name__}: (disconnected) at {id(self):#x}>'

Connection.__repr__:

py-amqp/amqp/connection.py

Lines 281 to 287 in 7300741

def __repr__(self):
if self._transport:
return f'<AMQP Connection: {self.host}/{self.virtual_host} '\
f'using {self._transport} at {id(self):#x}>'
else:
return f'<AMQP Connection: {self.host}/{self.virtual_host} '\
f'(disconnected) at {id(self):#x}>'

The full traceback:

ConnectionResetError: [Errno 104] Connection reset by peer
  File "celery/worker/loops.py", line 78, in asynloop
    update_qos()
  File "kombu/common.py", line 444, in update
    return self.set(self.value)
  File "kombu/common.py", line 437, in set
    self.callback(prefetch_count=new_value)
  File "celery/worker/consumer/tasks.py", line 43, in set_prefetch_count
    return c.task_consumer.qos(
  File "kombu/messaging.py", line 552, in qos
    return self.channel.basic_qos(prefetch_size,
  File "amqp/channel.py", line 1878, in basic_qos
    return self.send_method(
  File "amqp/abstract_channel.py", line 57, in send_method
    conn.frame_writer(1, self.channel_id, sig, args, content)
  File "amqp/method_framing.py", line 183, in write_frame
    write(view[:offset])
  File "amqp/transport.py", line 352, in write
    self._write(s)
BrokenPipeError: [Errno 32] Broken pipe
  File "kombu/message.py", line 128, in ack_log_error
    self.ack(multiple=multiple)
  File "kombu/message.py", line 123, in ack
    self.channel.basic_ack(self.delivery_tag, multiple=multiple)
  File "amqp/channel.py", line 1391, in basic_ack
    return self.send_method(
  File "amqp/abstract_channel.py", line 57, in send_method
    conn.frame_writer(1, self.channel_id, sig, args, content)
  File "amqp/method_framing.py", line 183, in write_frame
    write(view[:offset])
  File "amqp/transport.py", line 352, in write
    self._write(s)

I have not investigated why that is yet, but figured reporting it already is worth it, since having a proper (non-crashing) repr is more helpful during debugging/investigating issues, of course.

amqp 5.0.6 (but the code is the same in master)
sentry-sdk 1.1.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions