New submission from Enji Cooper <yaneurab...@gmail.com>:

The change made for bug 30378 caused a regression in our code by making
lookups for SysLogHandler addresses at init time, instead of making them more 
lazy. Example:

>>> import logging.handlers
>>> LOGGER = logging.getLogger("logger")
>>> LOGGER.addHandler(logging.handlers.SysLogHandler(address=('resolvessometimesbutnotthefirsttime.com',
>>>  logging.handlers.SYSLOG_UDP_PORT)))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/logging/handlers.py", line 767, in __init__
    ress = socket.getaddrinfo(host, port, 0, socktype)
socket.gaierror: [Errno -2] Name or service not known

This is exacerbated by the fact that a lot of code the organization I work for 
(and to be honest, I have written in the past) initializes global loggers once 
at import time. If the SysLogHandler is added to the global logger and the DNS 
resolution isn't possible (/etc/hosts is empty on Unix or does not contain the 
entry, and DNS out is to lunch), it will fall on its face at initialization 
time.

There needs to be a more graceful way of initializing loggers like this, or a 
way of delaying the host resolution, so it fails gracefully and doesn't crash 
the entire program (restoring the previous behavior).

Example: SMTPHandler doesn't do name resolution until it calls emit, which 
seems like a much more logical place to do the operation (especially since DNS 
records can change or become invalid).

----------
components: Library (Lib)
messages: 353775
nosy: calcheng, ngie
priority: normal
severity: normal
status: open
title: Fix for bug 30378 regressed SysLogHandler
type: crash
versions: Python 2.7, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38354>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to