405 communication protocol_error ai_generated true

AMQPConnectionError: connection closed by server (405) UNEXPECTED_FRAME

ID: communication/amqp-connection-closed-by-server

Also available as: JSON · Markdown · 中文
80%Fix Rate
87%Confidence
1Evidence
2024-04-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
AMQP 0-9-1 active
RabbitMQ 3.12 active
Pika 1.3 active

Root Cause

RabbitMQ or other AMQP broker closes the connection when a client sends a frame out of order, such as a basic.publish without a channel.open, or a heartbeat after connection.tune-ok.

generic

中文

RabbitMQ或其他AMQP代理在客户端发送无序帧时关闭连接,例如在没有channel.open的情况下发送basic.publish,或在connection.tune-ok之后发送心跳。

Official Documentation

https://www.rabbitmq.com/amqp-0-9-1-reference.html#connection.close

Workarounds

  1. 90% success Ensure the client opens a channel before publishing. In Pika, call channel = connection.channel() before any basic_publish. Verify the channel is not None and is open.
    Ensure the client opens a channel before publishing. In Pika, call channel = connection.channel() before any basic_publish. Verify the channel is not None and is open.
  2. 80% success Check for multiple threads sharing the same connection without synchronization. Use a connection per thread or add a lock around channel operations.
    Check for multiple threads sharing the same connection without synchronization. Use a connection per thread or add a lock around channel operations.

中文步骤

  1. Ensure the client opens a channel before publishing. In Pika, call channel = connection.channel() before any basic_publish. Verify the channel is not None and is open.
  2. Check for multiple threads sharing the same connection without synchronization. Use a connection per thread or add a lock around channel operations.

Dead Ends

Common approaches that don't work:

  1. Restart the RabbitMQ server to clear the error 95% fail

    The error is client-side; restarting the broker does not fix the client's frame ordering issue

  2. Increase the heartbeat interval on the client 85% fail

    Heartbeat timing is not the cause; the client is sending frames without proper channel initialization

  3. Use a different AMQP library (e.g., switch from Pika to Kombu) 80% fail

    The error is protocol-level, not library-specific; a different library will fail the same way if the frame sequence is wrong