ResourceLocked: Queue.declare: (405) RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'rpc.reply-standalone_rpc_proxy' ...
We're having on-and-off connectivity issues with RabbitMQ & nameko and occasionally we're seeing a ResourceLocked error bubbling up from inside kombu.
>>> n.rpc.browser_session_service.create()
^CTraceback (most recent call last):
File "<console>", line 1, in <module>
File "/venv/local/lib/python2.7/site-packages/nameko/rpc.py", line 352, in __call__
return reply.result()
File "/venv/local/lib/python2.7/site-packages/nameko/rpc.py", line 333, in result
self.resp_body = self.reply_event.wait()
File "/venv/local/lib/python2.7/site-packages/nameko/standalone/rpc.py", line 57, in wait
self.queue_consumer.get_message(self.correlation_id)
File "/venv/local/lib/python2.7/site-packages/nameko/standalone/rpc.py", line 163, in get_message
self._setup_consumer()
File "/venv/local/lib/python2.7/site-packages/nameko/standalone/rpc.py", line 93, in _setup_consumer
maybe_declare(self.queue, channel)
File "/venv/local/lib/python2.7/site-packages/kombu/common.py", line 113, in maybe_declare
return _maybe_declare(entity, declared, ident, channel)
File "/venv/local/lib/python2.7/site-packages/kombu/common.py", line 120, in _maybe_declare
entity.declare()
File "/venv/local/lib/python2.7/site-packages/kombu/entity.py", line 522, in declare
self.queue_declare(nowait, passive=False)
File "/venv/local/lib/python2.7/site-packages/kombu/entity.py", line 548, in queue_declare
nowait=nowait)
File "/venv/local/lib/python2.7/site-packages/amqp/channel.py", line 1259, in queue_declare
(50, 11), # Channel.queue_declare_ok
File "/venv/local/lib/python2.7/site-packages/amqp/abstract_channel.py", line 69, in wait
return self.dispatch_method(method_sig, args, content)
File "/venv/local/lib/python2.7/site-packages/amqp/abstract_channel.py", line 87, in dispatch_method
return amqp_method(self, args)
File "/venv/local/lib/python2.7/site-packages/amqp/channel.py", line 243, in _close
reply_code, reply_text, (class_id, method_id), ChannelError,
ResourceLocked: Queue.declare: (405) RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'rpc.reply-standalone_rpc_proxy-2e64ba30-447e-413e-a2d6-57e5db87fed5' in vhost 'staging-rpc-rabbitmq'
Has anyone seen anything like this?
This happens when you try to bind a new consumer to an exclusive queue.
Nameko uses exclusive, auto-delete queues in the RPC ReplyListener. Exclusive means a queue can have exactly one consumer. Auto-delete means the queue is removed when its last consumer disconnects. The queue should therefore be removed when the consumer disconnects.
Rabbit takes some time to reap the old queues though. It looks like the PollingQueueConsumer is reconnecting and redeclaring its queue before the old one has had a chance to be removed.
Are you using the stock standalone RPC proxy here, or some modified version of it?
There may be a bug here. Reconnecting to an exclusive queue seems to be asking for trouble. We want reply queues to be private to their consumers, but we also want to tolerate network glitches without losing replies.
I think the behaviour in the non-standalone case is different because we're using kombu's ConsumerMixin, which probably re-establishes the connection without replacing the consumer, meaning it doesn't violate the exclusivity rule.
Thanks for this in-depth explanation. I'd generally piece all this together, but it's good to have it laid out by someone who knows.
For the above traceback, we're using the stock standalone RPC (in the shell). That said, we're also seeing this issue in the non-standalone case. Here's a traceback for that:
Sep 20 18:03:22 IOError: Socket closed
Sep 20 18:03:22 Traceback (most recent call last):
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/kombu/mixins.py", line 177, in run
Sep 20 18:03:22 for _ in self.consume(limit=None): # pragma: no cover
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/nameko/messaging.py", line 404, in consume
Sep 20 18:03:22 conn.drain_events(timeout=safety_interval)
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/kombu/connection.py", line 275, in drain_events
Sep 20 18:03:22 return self.transport.drain_events(self.connection, **kwargs)
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 95, in drain_events
Sep 20 18:03:22 return connection.drain_events(**kwargs)
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/amqp/connection.py", line 303, in drain_events
Sep 20 18:03:22 chanmap, None, timeout=timeout,
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/amqp/connection.py", line 366, in _wait_multiple
Sep 20 18:03:22 channel, method_sig, args, content = read_timeout(timeout)
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/amqp/connection.py", line 337, in read_timeout
Sep 20 18:03:22 return self.method_reader.read_method()
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/amqp/method_framing.py", line 189, in read_method
Sep 20 18:03:22 raise m
Sep 20 18:03:22 Connection to broker lost, trying to re-establish connection...
Sep 20 18:03:22 Connected to amqp://account-service:**@aws-us-east-1-portal.12.dblayer.com:15353/staging-rpc-rabbitmq
Sep 20 18:03:22 Connection to broker lost, trying to re-establish connection...
Sep 20 18:03:22 Traceback (most recent call last):
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/kombu/mixins.py", line 177, in run
Sep 20 18:03:22 for _ in self.consume(limit=None): # pragma: no cover
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/nameko/messaging.py", line 398, in consume
Sep 20 18:03:22 with self.consumer_context(**kwargs) as (conn, channel, consumers):
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/kombu/mixins.py", line 186, in consumer_context
Sep 20 18:03:22 return self.gen.next()
Sep 20 18:03:22 File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
Sep 20 18:03:22 with self.Consumer() as (connection, channel, consumers):
Sep 20 18:03:22 File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
Sep 20 18:03:22 return self.gen.next()
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/kombu/mixins.py", line 235, in Consumer
Sep 20 18:03:22 with self._consume_from(*self.get_consumers(cls, channel)) as c:
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/nameko/messaging.py", line 349, in get_consumers
Sep 20 18:03:22 accept=self.accept)
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/kombu/messaging.py", line 364, in __init__
Sep 20 18:03:22 self.revive(self.channel)
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/kombu/messaging.py", line 376, in revive
Sep 20 18:03:22 self.declare()
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/kombu/messaging.py", line 386, in declare
Sep 20 18:03:22 ResourceLocked: Queue.declare: (405) RESOURCE_LOCKED - cannot obtain exclusive access to locked queue 'rpc.reply-account_service-6e82e969-bd52-4fea-996d-a2950479fb7c' in vhost 'staging-rpc-rabbitmq'
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/kombu/entity.py", line 522, in declare
Sep 20 18:03:22 self.queue_declare(nowait, passive=False)
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/kombu/entity.py", line 548, in queue_declare
Sep 20 18:03:22 nowait=nowait)
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/amqp/channel.py", line 1259, in queue_declare
Sep 20 18:03:22 (50, 11), # Channel.queue_declare_ok
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/amqp/abstract_channel.py", line 69, in wait
Sep 20 18:03:22 return self.dispatch_method(method_sig, args, content)
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/amqp/abstract_channel.py", line 87, in dispatch_method
Sep 20 18:03:22 return amqp_method(self, args)
Sep 20 18:03:22 File "/venv/local/lib/python2.7/site-packages/amqp/channel.py", line 243, in _close
Sep 20 18:03:22 reply_code, reply_text, (class_id, method_id), ChannelError,
Sep 20 18:03:22 queue.declare()
Sep 20 18:03:22 Connected to amqp://account-service:**@aws-us-east-1-portal.12.dblayer.com:15353/staging-rpc-rabbitmq
That said, it looks like in the non-standalone case, the error is logged, but also retried and the connection can be re-established.
This is interesting. It's not what I expected.
I wonder whether kombu is connecting with a new consumer, or simply that the old queue has been reaped by the time the second connection is made.
Do you have this in a reproducible test case?
Have exactly same error for exclusive queues stayed there after recovered from network partition. Clients have re-connected generating new exclusive queues. Old ones stays for some reason (they were not declared as durable). And when I try removing it from management UI, I get exact same error:
405 RESOURCE_LOCKED - cannot obtain exclusive access to locked
queue 'position-api-154787f3-cdf3-4e1c-a06c-3c2eb97fa3f8' in vhost '/'
P.S. To get out of network partition I restarted all nodes one by one start with those having least amount of active connections.
I've been thinking about this some more and I no longer believe that reply queues should be exclusive. If we dropped this constraint we'd be able to support temporarily disconnecting clients and avoid these error cases after a rabbit failure.
Related, if we also dropped auto-delete in preference of RabbitMQ's queue expiry policy, we'd be able to guarantee that clients reconnecting within a grace period won't lose replies (at the moment any reconnection will raise "disconnected waiting for reply" errors for all outstanding requests, since we assume the worst case scenario of the reply queue and message being auto-deleted)
@mattbennett but as a client side developer I can tell that it is sometimes easier to generate temporary reply queue names and not re-use.
@kuznero The reply queue name could still be guaranteed-unique and generated by the client (i.e. uuid-based). The difference would be that the client could tolerate a temporary outage and reconnect to that same queue using a different connection.
We experienced this issue today -- exclusive auto-delete queues that should have been automatically removed were not, and could not be manually be removed either. I guess there had been a network partition previously.
In our case the service stayed up, but the QueueConsumer for an RpcProxy DependencyProvider kept trying to reconnect. The expected behaviour is for the proxy to redeclare its reply queue, which it can only do once the previous one has been removed. Since the exclusive queue was never reaped by the broker, this "recoverable" error become unrecoverable and the service got stuck.
I don't know if the problem is tied to particular versions of RabbitMQ, but we're seeing it on 3.6.9.
I think this is more justification for dropping the exclusivity of the reply queue.
i wasn't aware of queue ttl. that sounds like a good fit for reply queues (the rabbitmq docs for this even mention "RPC-style reply queues"). it's been around since 2010 so should be safe enough to switch to and should be backwards compatible.
Any updates on this issue?
I intend to pick this up over the Christmas break or shortly thereafter
Hello @mattbennett I hope you are well. Have you got any time to look at this?
This has been merged with #504 and is available in the 2.9.0-rc0 pre-release which is on PyPI now.