From c3d6e9a42a74dc1f89e51797d67921f6be83d792 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9gory=20Wisniewski?= <gregory@nexedi.com>
Date: Mon, 26 Apr 2010 08:04:09 +0000
Subject: [PATCH] Lock the connection before processing pending packets.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2025 71dcc9de-d417-0410-9af5-da40c76e7ee4
---
 neo/event.py | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/neo/event.py b/neo/event.py
index a40b6d64..672aac04 100644
--- a/neo/event.py
+++ b/neo/event.py
@@ -91,13 +91,17 @@ class EpollEventManager(object):
             # See if there is anything to process
             to_process = self._getPendingConnection()
         if to_process is not None:
+            to_process.lock()
             try:
-                # Process
-                to_process.process()
+                try:
+                    # Process
+                    to_process.process()
+                finally:
+                    # ...and requeue if there are pending messages
+                    if to_process.hasPendingMessages():
+                        self._addPendingConnection(to_process)
             finally:
-                # ...and requeue if there are pending messages
-                if to_process.hasPendingMessages():
-                    self._addPendingConnection(to_process)
+                to_process.unlock()
 
     def _poll(self, timeout=1):
         rlist, wlist, elist = self.epoll.poll(timeout)
-- 
2.30.9