[issue17981] SysLogHandler closes connection before using it

2013-05-16 Thread Roundup Robot
Roundup Robot added the comment: New changeset d91da96a55bf by Vinay Sajip in branch '2.7': Issue #17981: Closed socket on error in SysLogHandler. http://hg.python.org/cpython/rev/d91da96a55bf New changeset 590b865aa73c by Vinay Sajip in branch '3.3': Issue #17981: Closed socket on error in SysL

[issue17981] SysLogHandler closes connection before using it

2013-05-16 Thread Richard Oudkerk
Richard Oudkerk added the comment: Rather than self.sock = None I would do self.sock.close() which should work better for non-refcounted Pythons. Of course it would be better to do this immediately after forking (i.e. before any more fds are created), otherwise you could still accid

[issue17981] SysLogHandler closes connection before using it

2013-05-16 Thread Vinay Sajip
Vinay Sajip added the comment: > The old socket's destructor closes the fd of the new socket. Aha! Nice one. But what's the correct fix? I suppose a self.sock = None before every self.sock = socket.socket call would fix seem this, and while I can certainly make this change in SysLogHandler, i

[issue17981] SysLogHandler closes connection before using it

2013-05-16 Thread Richard Oudkerk
Richard Oudkerk added the comment: The line sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) overwrites the old broken socket with a new one with the same fd. The old socket's destructor closes the fd of the new socket. -- nosy: +sbt __

[issue17981] SysLogHandler closes connection before using it

2013-05-16 Thread Vinay Sajip
Vinay Sajip added the comment: We'll try this with a simple script which doesn't use logging at all: import os import socket MSG1 = '<14>Hi, \x00' MSG2 = '<14>there!\x00' sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) sock.connect('/dev/log') sock.send(MSG1) os.close(sock.fileno()) #

[issue17981] SysLogHandler closes connection before using it

2013-05-16 Thread Vinay Sajip
Vinay Sajip added the comment: I see what you're saying now, but there's no explicit close in logging, so it's coming from somewhere lower down. Let's examine what happens when we try to emit the record: -> def emit(self, record): (Pdb) > /usr/lib/python2.7/logging/handlers.py(791)emit() -> m

[issue17981] SysLogHandler closes connection before using it

2013-05-16 Thread Julien Palard
Julien Palard added the comment: I understand the files_preserve parameter, the bug I'm filling is the innability of SysLogHandler to reopen the socket, although it tries : // DaemonContext closing all FDs: close(3)= 0 close(2)= 0

[issue17981] SysLogHandler closes connection before using it

2013-05-16 Thread Vinay Sajip
Vinay Sajip added the comment: The python-daemon documentation states, about files_preserve: "Elements of the list are file descriptors (as returned by a file object's `fileno()` method) or Python `file` objects. Each specifies a file that is not to be closed during daemon start." Notice that

[issue17981] SysLogHandler closes connection before using it

2013-05-15 Thread Josh Purvis
Josh Purvis added the comment: Ironically, I ran into this same exact issue today, and I have investigated the `files_preserve` param, with no luck. I'm not too familiar with the internals here, but from what I can tell it works with FileHandler, but not the SysLogHandler. If you try to add

[issue17981] SysLogHandler closes connection before using it

2013-05-15 Thread Vinay Sajip
Vinay Sajip added the comment: Isn't this a case of handles being closed in the child after a fork, by the daemon module? Have you investigated the files_preserve option in DaemonContext? -- resolution: -> invalid status: open -> pending ___ Python

[issue17981] SysLogHandler closes connection before using it

2013-05-15 Thread Josh Purvis
Changes by Josh Purvis : -- nosy: +Josh.Purvis ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.pyth

[issue17981] SysLogHandler closes connection before using it

2013-05-15 Thread Terry J. Reedy
Changes by Terry J. Reedy : -- nosy: +vinay.sajip ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.p

[issue17981] SysLogHandler closes connection before using it

2013-05-15 Thread Julien Palard
New submission from Julien Palard: I have a script that close its socket to /dev/log immediatly before using it, causing it to fail, here is the code : {{{ #!/usr/bin/env python # -*- coding: utf-8 -*- import logging import logging.handlers import daemon from daemon.pidlockfile import PIDLockFil