[issue15179] An infinite loop happens when we use SysLogHandler with eventlet

Kazutaka Morita report at bugs.python.org
Mon Jun 25 13:29:31 CEST 2012


New submission from Kazutaka Morita <morita.kazutaka at gmail.com>:

If we stop a syslog daemon when running the following program, it
leads to an infinite loop.

==
#!/usr/bin/env python

import eventlet
from logging.handlers import SysLogHandler
import time
import logging

eventlet.patcher.monkey_patch(all=False, socket=True)

logger = logging.getLogger('log')
logger.addHandler(SysLogHandler('/dev/log'))

while True:
    print "send a message to logger"
    logger.error("syslog test")
    time.sleep(1)
==

It is because there is a close leak in the python logging module, and
SysLogHandler continues to send a log message against the closed
connection forever.

The following patch seems to fix this problem:

diff -r 3b5545ba6432 Lib/logging/handlers.py
--- a/Lib/logging/handlers.py	Wed Jun 13 22:15:26 2012 -0400
+++ b/Lib/logging/handlers.py	Mon Jun 25 20:27:46 2012 +0900
@@ -801,7 +801,11 @@
         except socket.error:
             self.socket.close()
             self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-            self.socket.connect(address)
+            try:
+                self.socket.connect(address)
+            except socket.error:
+                self.socket.close()
+                raise
 
     def encodePriority(self, facility, priority):
         """

----------
components: Library (Lib)
messages: 163939
nosy: Kazutaka.Morita
priority: normal
severity: normal
status: open
title: An infinite loop happens when we use SysLogHandler with eventlet
type: behavior
versions: Python 2.7, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15179>
_______________________________________


More information about the Python-bugs-list mailing list