Commit 397410c9 authored by Vincent Pelletier's avatar Vincent Pelletier

Make it easier to debug cases where conn.getConnector() returns None.

This happens from time to time in tests, most probably during shutdown as
it doesn't make tests fail. This will help tracking this bug down.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@1666 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 463d6a03
...@@ -26,6 +26,8 @@ from neo.connector import ConnectorException, ConnectorTryAgainException, \ ...@@ -26,6 +26,8 @@ from neo.connector import ConnectorException, ConnectorTryAgainException, \
from neo.util import dump from neo.util import dump
from neo.logger import PACKET_LOGGER from neo.logger import PACKET_LOGGER
from neo import attributeTracker
def not_closed(func): def not_closed(func):
def decorator(self, *args, **kw): def decorator(self, *args, **kw):
if self.connector is None: if self.connector is None:
...@@ -134,6 +136,14 @@ class BaseConnection(object): ...@@ -134,6 +136,14 @@ class BaseConnection(object):
def hasPendingMessages(self): def hasPendingMessages(self):
return False return False
def whoSetConnector(self):
"""
Debugging method: call this method to know who set the current
connector value.
"""
return attributeTracker.whoSet(self, 'connector')
attributeTracker.track(BaseConnection)
class ListeningConnection(BaseConnection): class ListeningConnection(BaseConnection):
"""A listen connection.""" """A listen connection."""
......
...@@ -232,25 +232,33 @@ class EpollEventManager(object): ...@@ -232,25 +232,33 @@ class EpollEventManager(object):
pass pass
def addReader(self, conn): def addReader(self, conn):
fd = conn.getConnector().getDescriptor() connector = conn.getConnector()
assert connector is not None, conn.whoSetConnector()
fd = connector.getDescriptor()
if fd not in self.reader_set: if fd not in self.reader_set:
self.reader_set.add(fd) self.reader_set.add(fd)
self.epoll.modify(fd, 1, fd in self.writer_set) self.epoll.modify(fd, 1, fd in self.writer_set)
def removeReader(self, conn): def removeReader(self, conn):
fd = conn.getConnector().getDescriptor() connector = conn.getConnector()
assert connector is not None, conn.whoSetConnector()
fd = connector.getDescriptor()
if fd in self.reader_set: if fd in self.reader_set:
self.reader_set.remove(fd) self.reader_set.remove(fd)
self.epoll.modify(fd, 0, fd in self.writer_set) self.epoll.modify(fd, 0, fd in self.writer_set)
def addWriter(self, conn): def addWriter(self, conn):
fd = conn.getConnector().getDescriptor() connector = conn.getConnector()
assert connector is not None, conn.whoSetConnector()
fd = connector.getDescriptor()
if fd not in self.writer_set: if fd not in self.writer_set:
self.writer_set.add(fd) self.writer_set.add(fd)
self.epoll.modify(fd, fd in self.reader_set, 1) self.epoll.modify(fd, fd in self.reader_set, 1)
def removeWriter(self, conn): def removeWriter(self, conn):
fd = conn.getConnector().getDescriptor() connector = conn.getConnector()
assert connector is not None, conn.whoSetConnector()
fd = connector.getDescriptor()
if fd in self.writer_set: if fd in self.writer_set:
self.writer_set.remove(fd) self.writer_set.remove(fd)
self.epoll.modify(fd, fd in self.reader_set, 0) self.epoll.modify(fd, fd in self.reader_set, 0)
......
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