ebin123456 / py-amqplib

Automatically exported from code.google.com/p/py-amqplib
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Add missing shutdown call before socket close. #30

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
With the current code, if the programs exits soon after calling the close 
method on the transport, pending transmissions may be discarded. Adding the 
shutdown call before closing the socket asks the TCP stack to send all pending 
packets, and which fixes this problem.

Original issue reported on code.google.com by chr...@pianocktail.org on 26 May 2011 at 4:47

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, fixed in revision f777838afd2d with some extra code to help with SSL

Original comment by barry.pe...@gmail.com on 23 Jun 2011 at 12:58

GoogleCodeExporter commented 9 years ago
This fix causes my program, which has multiple threads with connections to the 
same RabbitMQ service,  to throw "[Errno 57] Socket is not connected" 
exceptions when trying to close any Connection after the first one is closed.  

I'm not an expert on this sort of thing, but a comment in this Stack Overflow 
thread

http://stackoverflow.com/questions/409783/socket-shutdown-vs-socket-close

suggests that "calling shutdown for reading and writing closes the underlying 
connection and sends a FIN / EOF to the peer regardless of how many processes 
have handles to the socket.".  

It would seem that the sock.shutdown() call is not appropriate in an 
environment where multiple threads might be sharing the socket, since when any 
of them closes its connection, the socket will be disconnected for all of the 
other threads too.

Original comment by jgarb...@gmail.com on 23 Sep 2011 at 11:57

GoogleCodeExporter commented 9 years ago
I neglected to mention that I'm using SSL connections to the RabbitMQ service, 
if that matters in this case.

Original comment by jgarb...@gmail.com on 23 Sep 2011 at 11:58

GoogleCodeExporter commented 9 years ago
I guess with multithreaded code, the last thread only should call shutdown. But 
without a call to shutdown, messages and acks send just before the program 
(whether multi-threaded or not) terminates may be lost, so *some* call to 
shutdown is needed.

Original comment by chr...@pianocktail.org on 28 Sep 2011 at 3:46

GoogleCodeExporter commented 9 years ago
This library doesn't support multiple threads sharing the same Connection, 
you're really playing with fire there.  Even if we undid this patch, it could 
blow up in your face lots of other ways.  It's OK though if separate threads 
open separate Connections.

Original comment by barry.pe...@gmail.com on 28 Sep 2011 at 10:20