Replies: 2 comments 5 replies
-
You are sharing a channel between threads, which the docs very explicitly tell you not to do. Consider what would happen if you run Message count is taken from a |
Beta Was this translation helpful? Give feedback.
-
Finally i figured out how to circumvent the problem. This approach works right now quite fine for me:
First it didn't work smooth. I established the connection via a rails initializer, and then i could not confirm that it works, it always gave me a timeout. After disabling the spring preloader it worked quite fine, so it does now also in the prod environment. @michaelklishin thank you for your advice! |
Beta Was this translation helpful? Give feedback.
-
Hello Bunny team,
i faced an issue while trying to use the queue.message_count function.
We use a threaded puma server. In this we store the ruby bunny gem in a instance variable. During initialization we create a bunny connection that we store in a instance variable in a module, then we create to a queue, store this also inside of a instance variable and subscribe to a channel. Later we pick up this instance variable and call the #message_count function. Here is a minimal example that sketches what we are doing:
Now, our problem is that i sometimes (!) the #message_count function hangs for 30s and we see a timeout the error message:
The stdout shows:
Received a queue.declare-ok response for a mismatching queue (bar instead of ) on channel 1 possibly due to a timeout, ignoring it
With wireshark i confirmed that the queue declare request is sent, and the declare ok message is responded fast on the right queue name. It seems that the
@pending_queue_declare_name variable
gets lost somewhere on the way since this is used in thechannel.rb#handle_method (L1666)
.In some cases it works without error as it should, and in some it doesn't. My suspicion is that there is a thread safety problem somewhere. If the #meassage_count call is made by the thread that created the connection it works, if there is another thread calling it it fails. So i guess there is somewhere a problem with thread safety here.
What would you recommend as a workaround, or do you have any suggestions how to fix this problem?
Beta Was this translation helpful? Give feedback.
All reactions