majek / puka

Puka - the opinionated RabbitMQ client
https://github.com/majek/puka
Other
182 stars 34 forks source link

'Client' object has no attribute 'x_publish_promise' #5

Closed nickcash closed 13 years ago

nickcash commented 13 years ago

I'm randomly seeing this exception in my logs, when calling basic_publish. It seems to only happen once per several thousand publishes, so I'm yet to be able to reproduce it myself.

I have recently upgraded to 0.0.3, and I haven't seen this exception prior to upgrading.

majek commented 13 years ago

I'm afraid I need more details. Do you see anything suspicious in rabbitmq logs? What is your application doing (consiming? publishing? to one queue?, and so on). Can you paste full traceback? Can reproduce it with some kind of test case?

nickcash commented 13 years ago

I was hesitant to post this without much information, but I was hoping maybe something about that would jump out.

This app publishes to 4 different queues. The queues are durable, and messages have delivery_mode 2. It's only using the default "" exchange.

I actually do not have the full traceback, but I'll add some additional logging to acquire it.

The rabbitmq log reports "exception on TCP connection <0.15049.19> from 127.0.0.1:60894 connection_closed_abruptly", but I think that's to be expected when my app crashes.

I am not able to reproduce it. It seems to be completely random.

majek commented 13 years ago

If I can read the code, the only moment this kind of exception could occur is when you're trying to publish message just just after the connection was opened. Is that correct? Do you do a proper 'client.wait' after client.connect()? Like:

promise = client.connect()
client.wait(promise)
majek commented 13 years ago

Here you are. The exception:

$ python x.py 
Traceback (most recent call last):
  File "x.py", line 15, in <module>
    body="Hello world!")
  File "../puka/client.py", line 19, in wrapper
    t = method(*args, **kwargs)
  File "../puka/machine.py", line 94, in basic_publish
    pt = conn.x_publish_promise
AttributeError: 'Client' object has no attribute 'x_publish_promise'

The code

import puka
client = puka.Client("amqp://localhost/")
promise = client.connect()
#client.wait(promise)
promise = client.basic_publish(exchange='', routing_key='test',
                              body="Hello world!")
client.wait(promise)

Please do confirm that your code has a proper 'client.wait' just after 'client.connect'.

nickcash commented 13 years ago

I do a

client = puka.Client()
client.wait(client.connect())

at module import time, then within that module is a function to publish to that client. If I'm thinking correctly, the python module will block when imported until puka's client connects, so the function can't possibly be called before then. But I'm guessing there's some subtlety with the way that works and I'm missing something.

majek commented 13 years ago

I can't see a codepath that would produce this exception, except the one I showed you. Maybe the problem is with establishing the connection on module import? Maybe some other module has a 'publish' on import time? Or maybe a threading issue?

Can you move connection establishment from import-time to a singleton or something?

Also, please supply a python traceback.

majek commented 13 years ago

Were you able to trigger that again?

nickcash commented 13 years ago

Sorry for the lack of response. After some more checking, I'm pretty sure it's a threading issue.