This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: logging.config.dictConfig shuts down socket for existing SysLogHandlers
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.10, Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: flyte, iritkatriel, jmadden, sblondon, vinay.sajip, xtreak
Priority: normal Keywords:

Created on 2021-02-10 20:45 by flyte, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg386805 - (view) Author: Ellis Percival (flyte) Date: 2021-02-10 20:45
Since 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/", line 940, in emit
    self.socket.sendto(msg, self.address)
OSError: [Errno 9] Bad file descriptor
Call stack:
  File "/home/flyte/workspaces/python/", 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 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.
msg410832 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-01-17 23:19
I'm not getting this error on 3.11 on a Mac. Can you check on versions <= 3.9? Earlier versions are no longer getting bugfixes.
msg411284 - (view) Author: Stéphane Blondon (sblondon) * Date: 2022-01-22 19:32
I can reproduce the error on Debian/testing with:
- Python 3.9.9
- Python 3.10.0
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87362
2022-01-22 19:36:11iritkatrielsetversions: + Python 3.9, Python 3.10, - Python 3.7, Python 3.8
2022-01-22 19:32:44sblondonsetstatus: pending -> open
nosy: + sblondon
messages: + msg411284

2022-01-17 23:19:54iritkatrielsetstatus: open -> pending

nosy: + iritkatriel
messages: + msg410832

type: crash -> behavior
2021-02-11 14:06:15xtreaksetnosy: + vinay.sajip, xtreak
2021-02-11 14:02:21jmaddensetnosy: + jmadden
2021-02-10 20:45:36flytecreate