-
Notifications
You must be signed in to change notification settings - Fork 843
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
connection be dropped when long running task in blocking connection #418
Comments
I'm seeing the same thing, even when specifying heartbeat_interval in my connection params. |
@modeyang, a pika connection runs entirely in the user's thread. So, if you don't call it's API periodically, you're not letting it deal with events, including heartbeats. Blocking connection has |
@vitaly-krugl can you give me example for this situation? using mutli-threads, one for real worker, another for events? |
@modeyang, the trick here is acknowledging the message before the heartbeat expires, right? Have you tried configuring heartbeat for a much longer interval - long enough to process your longest task? Also, a multi-threaded solution could work, as long as you're not accessing the connection/channel from multiple threads; here is an example of how it could work: Consumer thread:
Worker thread:
|
In addition to my earlier comment, it's now possible to set longer heartbeat timeouts via PR #666, which is now in Pika master (but not released yet). Please try out the version from Pika's master branch, including setting a longer heartbeat timeout, and open a new issue if you're still having trouble with it. |
I'm starting to get the same error even when I adjust the heartbeat connection parameter. My code Is essentially identical to the one above and the error I receive is this: |
See comment #892 (comment) |
|
We're trying to set up a topic queue system where a producer will generate several tasks and one or more consumers will grab a task at a time, process it, and acknowledge the message.
The problem is, some task will run over 10 minutes(in rabbitmq 3.*, Server side has heartbeat parameters, default 10 minutes .http://www.rabbitmq.com/configure.html), and we're not responding to messages at that time, causing the server to disconnect us.
Here's some pseudo code for our consumer:
!/usr/bin/env python
import pika
import time
connection = pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel = connection.channel()
channel.queue_declare(queue='task_queue', durable=True)
def callback(ch, method, properties, body):
long_running_task(body)
ch.basic_ack(delivery_tag = method.delivery_tag)
channel.basic_qos(prefetch_count=1)
channel.basic_consume(callback,
queue='task_queue')
channel.start_consuming()
I refer the source of pika in the function of start_consuming, that seems only one thread process read/write event, so I suspect that it will block the heartbeat respond to mq sever when running a long task over 600 seconds.
I'm sorry if my mistake, any one confronted the same issue, and you how to solve it ? thanks a lot.
The text was updated successfully, but these errors were encountered: