mbroadst / qamqp

AMQP 0.9.1 implementation for Qt
Other
151 stars 127 forks source link

Mass-publishing messages results in QAbstractSocket::UnconnectedState #57

Open J4nsen opened 7 years ago

J4nsen commented 7 years ago

Hi, I'm emitting a lot of JSON messages from a thread (QAmqpClient runs in the main thread). About 100k-500k in less than 10s. The first 50k messages are correctly received by the exchange. After that the connection to RabbitMQ gets disconnected:

[11:33:31] unknown: void QAmqpClientPrivate::sendFrame(const QAmqpFrame&) socket not connected: QAbstractSocket::UnconnectedState

Disabling confirms delays the problem a little bit, and waitForConfirms + enabling confirms results in a segmentation fault (Have not analyzed this further).

This is my class which publishes the messages: https://gist.github.com/J4nsen/40da0d436e4f8e00dbdbb5cc0860b20f

What is the best way to fix this problem? Implement a local queue/rate limiter and give the main thread some time for its main event loop? Or should I investigate in segfault with waitForConfirms?

Thanks, Jan

J4nsen commented 7 years ago

The first error message is this one:

[15:22:12] unknown: <- basic#publish( exchange=direct_nodes, routing-key=node_63cf1623a636, mandatory=0, immediate=0 ) [15:22:12] unknown: <- basic#publish( exchange=direct_nodes, routing-key=node_823ec6a0e813, mandatory=0, immediate=0 ) [15:22:13] unknown: socket error: "Network operation timed out" [15:22:13] unknown: exchange disconnected: "direct_nodes" [15:22:13] unknown: void QAmqpClientPrivate::sendFrame(const QAmqpFrame&) socket not connected: QAbstractSocket::UnconnectedState [15:22:13] unknown: void QAmqpClientPrivate::sendFrame(const QAmqpFrame&) socket not connected: QAbstractSocket::UnconnectedState [15:22:13] unknown: <- basic#publish( exchange=direct_nodes, routing-key=node_63cf1623a636, mandatory=0, immediate=0 ) [15:22:13] unknown: void QAmqpClientPrivate::sendFrame(const QAmqpFrame&) socket not connected: QAbstractSocket::UnconnectedState

mbroadst commented 7 years ago

@J4nsen sounds like maybe rabbitmq is cutting off the connection, is there anything in the logs on the side of the equation?

KonstantinZvyagin commented 7 years ago

I got similar problem. When i send a lot of large messages RebbitMq drops connection. Firs of all we have to look RabbitMq server log. It's look's like RabbitMq bug. Can You publish you log after you got error ?

J4nsen commented 6 years ago

Hey, sorry for not reporting back. I implemented the local queue/rate limiter which I talked about in my first post and didn't encounter the hang again :/. If I find the time, I will try to reproduce the original problem.

manner82 commented 6 years ago

Hi,

I have also bumbed into this issue, and it is the client which is closing connection: rabbit logs: client unexpectedly closed TCP connection

This workaround seems to be working: client.setWriteTimeout(-2); // where client is the QAmqpClient.

Note: specifying -1 seems to mean "wait forever when sending a frame". Lower than -1 means, do not wait. Default seems to be 1000ms which seems to be not enough when mass publishing.