txamqp.protocol.AMQClient.close() not closing underlying transport

Bug #940576 reported by MT
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
txAMQP
Fix Released
Medium
Unassigned

Bug Description

Making a call to client.close() leaves an open socket to txamqp. Background, I have a twisted.web resource that connects to a rabbitmq and inspects the current sizes of a set of queues. After transmitting a response, the resource closes the txamqp channel and client it opened. However, today I realized that the underlying socket connection to txamqp remains open. Doing an lsof -i prints out:

TCP localhost.localdomain:58318->localhost.localdomain:amqp (ESTABLISHED)
TCP localhost.localdomain:38437->localhost.localdomain:amqp (ESTABLISHED)

This list continues to grow as I make more requests against the resource. After some debugging, I noticed that the txamqp client isn't actually calling close on the underlying transport. In order to close the sockets, I am forced to explicity call transport.loseConnection(). My code is now as follows:

client.close('Shutting down client')
client.transport.loseConnection()

I would expect client.close('reason') to perform the underlying transport loseConnection for me. I am using the following code to connect to RabbitMQ:

d = ClientCreator(reactor, AMQClient, delegate=TwistedDelegate(), vhost="/", spec=spec).connectTCP(host, port)

Thus I end up with a reference to a txamqp.protocol.AMQClient, which is the class I am calling close on. My propsed fix would be for the close() method of the AMQClient class to explicity call self.transport.loseConnection() after closing the delegate.

Apologies ahead of time if i'm doing something dumb ;).

Revision history for this message
Esteve Fernandez (esteve) wrote :

Fixed in trunk. I applied your change and it works, thanks!

Changed in txamqp:
importance: Undecided → Medium
status: New → Fix Committed
Revision history for this message
Aurélien Bompard (aurelien-bompard) wrote :

The committed fix does not work, I get this traceback :

  File "/usr/lib64/python2.6/site-packages/twisted/internet/tcp.py", line 680, in connectionLost
    Connection.connectionLost(self, reason)
  File "/usr/lib64/python2.6/site-packages/twisted/internet/tcp.py", line 520, in connectionLost
    protocol.connectionLost(reason)
  File "/usr/lib/python2.6/site-packages/txamqp/protocol.py", line 380, in connectionLost
    self.close(reason)
  File "/usr/lib/python2.6/site-packages/txamqp/protocol.py", line 292, in close
    self.delegate.close(reason)
  File "/usr/lib/python2.6/site-packages/txamqp/client.py", line 110, in close
    self.transport.loseConnection()
exceptions.AttributeError: 'TwistedDelegate' object has no attribute 'transport'

It should be :

    self.client.transport.loseConnection()

Revision history for this message
Esteve Fernandez (esteve) wrote :

Thanks for noticing Aurélien. I just committed a fix and made a new release.

Changed in txamqp:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.