Skip to content

Commit

Permalink
Avoid hanging forever when the socket goes away and the only thing we…
Browse files Browse the repository at this point in the history
…'re doing is writing.

If the connection closed during a flush_outbound with pending data, we
were in some cases (asyncore-based) looping forever. Checking each
time we enter the loop gets us a sensible exception in these cases.
  • Loading branch information
tonyg committed Nov 15, 2011
1 parent b1d1cbf commit 6114707
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pika/asyncore_adapter.py
Expand Up @@ -54,6 +54,7 @@
from heapq import heappush, heappop
from errno import EAGAIN
import pika.connection
from pika.exceptions import *

class RabbitDispatcher(asyncore.dispatcher):
def __init__(self, connection):
Expand Down Expand Up @@ -108,6 +109,9 @@ def disconnect_transport(self):

def flush_outbound(self):
while self.outbound_buffer:
if self.connection_close:
# The connection was closed while we weren't looking!
raise ConnectionClosed(self.connection_close)
self.drain_events()

def drain_events(self):
Expand Down

0 comments on commit 6114707

Please sign in to comment.