Skip to content

Instantly share code, notes, and snippets.

@nvllsvm
Last active August 6, 2019 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nvllsvm/65e5f78347fa58f7e48dcafa0bef1c0c to your computer and use it in GitHub Desktop.
Save nvllsvm/65e5f78347fa58f7e48dcafa0bef1c0c to your computer and use it in GitHub Desktop.
version: '2.4'
services:
example:
image: python:alpine
command: ['sh', '-c', 'pip install rabbitpy && python /example/example.py']
volumes:
- ./:/example
rabbitmq:
image: rabbitmq:alpine
ports:
- 5672:5672
- 15672:15672
import rabbitpy
import sys
import time
if sys.platform == 'darwin':
url = 'amqp://guest:guest@localhost:5672/%2f'
else:
url = 'amqp://guest:guest@rabbitmq:5672/%2f'
conn = rabbitpy.Connection(url)
channel = conn.channel()
# manually enable this later
## channel.enable_publisher_confirms()
while True:
print('Publishing!')
message = rabbitpy.Message(channel, b'content')
message.publish('amq.topic', 'rk')
time.sleep(5)
@nvllsvm
Copy link
Author

nvllsvm commented Jul 19, 2019

Testing

Setup

$ pip install rabbitpy
$ docker-compose up -d rabbitmq

⚠️ Make sure that the rabbitmq container is fully started before continuing.

Running in Docker (Linux)

$ docker-compose run example
Publishing!
Publishing!
...

Running locally (macOS)

$ python test.py
Publishing!
Publishing!
...

Replicating the Issue

After two successful Publishing! messages, execute the following command:

$ docker-compose kill rabbitmq

On Docker, you'll get the expected exception:

Publishing!
Publishing!
Traceback (most recent call last):
  File "/example/example.py", line 16, in <module>
    message.publish('amq.topic', 'rk')
  File "/usr/local/lib/python3.7/site-packages/rabbitpy/message.py", line 284, in publish
    self.channel.write_frames(frames)
  File "/usr/local/lib/python3.7/site-packages/rabbitpy/base.py", line 265, in write_frames
    if self._can_write():
  File "/usr/local/lib/python3.7/site-packages/rabbitpy/base.py", line 285, in _can_write
    self._check_for_exceptions()
  File "/usr/local/lib/python3.7/site-packages/rabbitpy/base.py", line 313, in _check_for_exceptions
    raise exception
rabbitpy.exceptions.ConnectionResetException: Connection was reset at socket level

On macOS, you'll continue to see the Publishing! messages printed indefinitely.

Hypothesis

There seems to be a missing read timeout of some sort.

The example so far has not had publisher confirmations enable. With them enabled, the macOS example hangs indefinitely.

@gmr
Copy link

gmr commented Aug 6, 2019

There's not a missing timeout, as the timeout value is the same for READ, WRITE, and ERROR:

https://github.com/gmr/rabbitpy/blob/master/rabbitpy/io.py#L85

it's the difference between kqueue and poll. I've not been in this code for some time, but it's likely around event registration and may even be a Python level bug. I'm poking around on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment