Commit 8bf149d0 authored by Julien Muchembled's avatar Julien Muchembled

More generic handling of closed MTConnection with pending requests

This optimizes the normal case, and handlers can now take specific action
when requests are cancelled because a connection is closed.
parent 3bd82ef1
......@@ -172,9 +172,6 @@ class Application(ThreadedApplication):
conn, packet, kw = get(block)
except Empty:
break
if packet is None:
# connection was closed
continue
block = False
try:
_handlePacket(conn, packet, kw)
......
......@@ -19,6 +19,16 @@ from .locking import Lock, Empty
EMPTY = {}
NOBODY = []
@apply
class _ConnectionClosed(object):
handler_method_name = 'connectionClosed'
decode = tuple
class getId(object):
def __eq__(self, other):
return True
def giant_lock(func):
def wrapped(self, *args, **kw):
self.lock_acquire()
......@@ -89,7 +99,7 @@ class Dispatcher:
continue
queue_id = id(queue)
if queue_id not in notified_set:
queue.put((conn, None, None))
queue.put((conn, _ConnectionClosed, EMPTY))
notified_set.add(queue_id)
_decrefQueue(queue)
......
......@@ -16,6 +16,7 @@
import sys
from . import logging
from .connection import ConnectionClosed
from .protocol import (
NodeStates, Packets, Errors, BackendNotImplemented,
BrokenNodeDisallowedError, NotReadyError, PacketMalformedError,
......@@ -261,3 +262,6 @@ class AnswerBaseHandler(EventHandler):
def acceptIdentification(*args):
pass
def connectionClosed(self, conn):
raise ConnectionClosed
......@@ -17,7 +17,6 @@
import thread, threading, weakref
from . import logging
from .app import BaseApplication
from .connection import ConnectionClosed
from .debug import register as registerLiveDebugger
from .dispatcher import Dispatcher
from .locking import SimpleQueue
......@@ -141,14 +140,8 @@ class ThreadedApplication(BaseApplication):
_handlePacket = self._handlePacket
while True:
qconn, qpacket, kw = get(True)
if conn is qconn:
# check fake packet
if qpacket is None:
raise ConnectionClosed
if msg_id == qpacket.getId():
if conn is qconn and msg_id == qpacket.getId():
_handlePacket(qconn, qpacket, kw, handler)
break
elif qpacket is None:
continue
_handlePacket(qconn, qpacket, kw)
return self.getHandlerData()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment