FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.14] gh-82535: Ignore address resolution failure in SysLogHandler constructor (GH-154504) by miss-islington · Pull Request #155458 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 5 additions & 1 deletion Lib/logging/handlers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,11 @@ def __init__(self, address=('localhost', SYSLOG_UDP_PORT),
self.socktype = socktype
self.timeout = timeout
self.socket = None
self.createSocket()
# The address is resolved again when emitting an event.
try:
self.createSocket()
except socket.gaierror:
pass

def _connect_unixsocket(self, address):
use_socktype = self.socktype
Expand Down
18 changes: 18 additions & 0 deletions Lib/test/test_logging.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,24 @@ def tearDown(self):
self.server_class.address_family = socket.AF_INET
super(IPv6SysLogHandlerTest, self).tearDown()

@support.requires_working_socket()
class UnresolvableSysLogAddressTest(BaseTest):

"""Test for SysLogHandler with a temporarily unresolvable address."""

@patch('socket.getaddrinfo')
def test_unresolvable_address(self, mock_getaddrinfo):
# The address can be unresolvable when the handler is created.
mock_getaddrinfo.side_effect = socket.gaierror
hdlr = logging.handlers.SysLogHandler(('localhost', 514))
self.addCleanup(hdlr.close)
self.assertIsNone(hdlr.socket)
# It is resolved again when a record is emitted.
calls = mock_getaddrinfo.call_count
with support.captured_stderr():
hdlr.emit(logging.makeLogRecord({'msg': 'sp\xe4m'}))
self.assertGreater(mock_getaddrinfo.call_count, calls)

@support.requires_working_socket()
@threading_helper.requires_working_threading()
class HTTPHandlerTest(BaseTest):
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:class:`logging.handlers.SysLogHandler` no longer fails
if the address cannot be resolved when the handler is created.
The address is resolved again when a record is emitted.
Loading

Back | FazBrowse Home | New Git URL