[New-bugs-announce] [issue43196] logging.config.dictConfig shuts down socket for existing SysLogHandlers

Ellis Percival report at bugs.python.org
Wed Feb 10 15:45:36 EST 2021

New submission from Ellis Percival <python.org at failcode.co.uk>:

Since https://github.com/python/cpython/commit/b6c1989168efeb8b6320bec958e7e339270ac0ce dictConfig (and presumably fileConfig) has called logging.shutdown() on the existing handlers.

This causes existing SysLogHandlers' sockets to be closed, which then causes a BadFileDescriptor error when you try to use it:

--- Logging error ---
Traceback (most recent call last):
  File "/usr/lib/python3.8/logging/handlers.py", line 940, in emit
    self.socket.sendto(msg, self.address)
OSError: [Errno 9] Bad file descriptor
Call stack:
  File "/home/flyte/workspaces/python/test.py", line 18, in <module>

Reproduce the error with the following code:

import logging.config
import socket
from logging.handlers import SysLogHandler

log = logging.getLogger("logtest")
syslog_handler = SysLogHandler(("", 12345), socktype=socket.SOCK_DGRAM)


        "version": 1,
        "disable_existing_loggers": False,


This causes issues such as https://github.com/benoitc/gunicorn/issues/2073 where gunicorn sets up a SysLogHandler, then when any app (Django does it by default) calls dictConfig() it closes the socket used by gunicorn's SysLogHandler.

Assuming this also affects Python 3.9 and 3.10, but untested.

components: Library (Lib)
messages: 386805
nosy: flyte
priority: normal
severity: normal
status: open
title: logging.config.dictConfig shuts down socket for existing SysLogHandlers
type: crash
versions: Python 3.7, Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list