Pika's IndexError: pop from an empty deque

352 views
Skip to first unread message

Yash Mistry

unread,
Apr 4, 2023, 5:45:50 AM4/4/23
to Pika
Hello everyone,

I am facing an error while using the Pika library to communicate with RabbitMQ. I am trying to publish message from my python script and it's also publishing the messages correctly but I have receiving an some error (which I can't debug).

Screenshot from 2023-04-04 15-11-39.png
Screenshot from 2023-04-04 15-11-57.png
Screenshot from 2023-04-04 15-12-05.png
Screenshot from 2023-04-04 15-12-10.png

Here's some useful information about the version,

Python version: 3.8
Pika version: 1.3.1
RabbitMQ version: 3.11.7
OS: Ubuntu

Please let me know if you need more help

Thank you,
Yash Mistry

Yash Mistry

unread,
Apr 4, 2023, 6:08:36 AM4/4/23
to Pika
Code Snippet:

import pika
usr_pwd = pika.PlainCredentials('admin', 'admin')
connection = pika.BlockingConnection(pika.ConnectionParameters(host=self.host, port=self.port,
credentials=usr_pwd, socket_timeout=50,
heartbeat=50))
channel = connection.channel()
channel.confirm_delivery()
channel.exchange_declare(exchange=_user, exchange_type='fanout', durable=True)
channel.basic_publish(exchange=_user, routing_key='', body=str(data))

Luke Bakken

unread,
Apr 10, 2023, 10:53:51 AM4/10/23
to Pika
Hello,

Please provide a file with stack traces. Your screenshots are very small and difficult to read.

Related issues:

Your code is so simple I doubt the problem lies with Pika. What does RabbitMQ log? Please attach the complete log file.

Thanks,
Luke

Yash Mistry

unread,
Apr 11, 2023, 3:49:18 AM4/11/23
to Pika
here's log txt: LOGS

Luke Bakken

unread,
Apr 11, 2023, 9:28:19 AM4/11/23
to Pika
Thanks,

"Unexpected frame" suggests a bug in how your code is using Pika. Please provide all of your code in a git repository I can clone to see it. Screenshots are not acceptable.

Thanks,
Luke

Yash Mistry

unread,
Apr 12, 2023, 1:49:52 AM4/12/23
to pika-...@googlegroups.com
Hey Luke,

Thank you for looking into my concern. As I am working on a certain project which has an NDA so I can't give you the whole code but I have created a module for this specific RabbitMQ Publish which I am going to provide in attachment.

To test that,

1. Create run.py
2. Import the RabbitMQ class and create an instance and call the publish_to_staff method using required arguments'.

Note:
-> RabbitMQ service is running in a Docker container.


--
You received this message because you are subscribed to a topic in the Google Groups "Pika" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pika-python/pu9lywg6Jks/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pika-python...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pika-python/c1ea1b9b-8461-4b4f-9f92-f7c5006a4c9dn%40googlegroups.com.

Luke Bakken

unread,
Apr 12, 2023, 10:38:40 AM4/12/23
to Pika
I've imported your code here and have made some minor changes - https://github.com/lukebakken/pika-empty-deque-pu9lywg6Jks

Note that in the future, if you have issues with any software, providing a git repository that someone can clone and run is very helpful. It may not seem like much but it would have saved me some time.

When I run the code, I do not see the issue. Please provide exact instructions for reproducing the issue you report.

Thanks,
Luke

Yash Mistry

unread,
Apr 12, 2023, 10:55:52 AM4/12/23
to pika-...@googlegroups.com
Hey Luke,

First of thank you. As I can see you made some minor changes in the code.

But as per knowledge the changes you have made will not impact on actual running.

As I have said before I'm running RabbitMQ in Docker container. 

Normally it's code runs smoothly without any error but when I give extra load using load testing tool like Locust, it's runs very well but in between sometime it's give error regarding StreamLostError. 

From next time onwards, I'll surely submit the code in repository. 

Thank you again for your support,
Yash Mistry 

 04-Apr-23 09:23:57 -- pika.adapters.utils.io_services_utils -- _on_socket_writable --  _AsyncBaseTransport._produce() failed, aborting connection: error=IndexError('pop from
 an empty deque'); sock=<socket.socket fd=1077, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('10.233.72.139', 46224), raddr=('10.9.2.8', 31006)>
; Caller's stack:                                                   Traceback (most recent call last):                                                                                   
  File "/root/.local/lib/python3.8/site-packages/pika/adapters/utils/io_services_utils.py", line 1103, in _on_socket_writable
    self._produce()                                                                                                   
  File "/root/.local/lib/python3.8/site-packages/pika/adapters/utils/io_services_utils.py", line 822, in _produce  
    chunk = self._tx_buffers.popleft()                                                                             
IndexError: pop from an empty deque                                      
Traceback (most recent call last):      
  File "/root/.local/lib/python3.8/site-packages/pika/adapters/utils/io_services_utils.py", line 1103, in _on_socket_writable
    self._produce()                           
  File "/root/.local/lib/python3.8/site-packages/pika/adapters/utils/io_services_utils.py", line 822, in _produce      
    chunk = self._tx_buffers.popleft()                                                                             
IndexError: pop from an empty deque                                       
 04-Apr-23 09:23:57 -- pika.adapters.base_connection -- _proto_connection_lost --  connection_lost: StreamLostError: ("Stream connection lost: IndexError('pop from an empty d
eque')",)

--
You received this message because you are subscribed to a topic in the Google Groups "Pika" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pika-python/pu9lywg6Jks/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pika-python...@googlegroups.com.

Luke Bakken

unread,
Apr 12, 2023, 10:58:32 AM4/12/23
to Pika
Hey Yash -

Please fork my repository and make the necessary changes so that I can run the code in the same manner you are, via Locust.

Then, open a pull request so I can merge those changes and see the same thing as you.

I am happy to help find the cause of this issue, but I do not have time to guess how to reproduce it.

Running RabbitMQ in docker isn't the root cause of this issue.

Thanks -
Luke

On Wednesday, April 12, 2023 at 7:55:52 AM UTC-7 Yash Mistry wrote:
Hey Luke,

Reply all
Reply to author
Forward
0 new messages