| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 87b120f commit c294654
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -902,7 +902,11 @@ def __init__(self, address=('localhost', SYSLOG_UDP_PORT), | |||
| 902 | 902 | self.socktype = socktype | |
| 903 | 903 | self.timeout = timeout | |
| 904 | 904 | self.socket = None | |
| 905 | - self.createSocket() | ||
| 905 | + # The address is resolved again when emitting an event. | ||
| 906 | + try: | ||
| 907 | + self.createSocket() | ||
| 908 | + except socket.gaierror: | ||
| 909 | + pass | ||
| 906 | 910 | ||
| 907 | 911 | def _connect_unixsocket(self, address): | |
| 908 | 912 | use_socktype = self.socktype | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2211,6 +2211,24 @@ def tearDown(self): | |||
| 2211 | 2211 | self.server_class.address_family = socket.AF_INET | |
| 2212 | 2212 | super(IPv6SysLogHandlerTest, self).tearDown() | |
| 2213 | 2213 | ||
| 2214 | + @support.requires_working_socket() | ||
| 2215 | + class UnresolvableSysLogAddressTest(BaseTest): | ||
| 2216 | + | ||
| 2217 | + """Test for SysLogHandler with a temporarily unresolvable address.""" | ||
| 2218 | + | ||
| 2219 | + @patch('socket.getaddrinfo') | ||
| 2220 | + def test_unresolvable_address(self, mock_getaddrinfo): | ||
| 2221 | + # The address can be unresolvable when the handler is created. | ||
| 2222 | + mock_getaddrinfo.side_effect = socket.gaierror | ||
| 2223 | + hdlr = logging.handlers.SysLogHandler(('localhost', 514)) | ||
| 2224 | + self.addCleanup(hdlr.close) | ||
| 2225 | + self.assertIsNone(hdlr.socket) | ||
| 2226 | + # It is resolved again when a record is emitted. | ||
| 2227 | + calls = mock_getaddrinfo.call_count | ||
| 2228 | + with support.captured_stderr(): | ||
| 2229 | + hdlr.emit(logging.makeLogRecord({'msg': 'sp\xe4m'})) | ||
| 2230 | + self.assertGreater(mock_getaddrinfo.call_count, calls) | ||
| 2231 | + | ||
| 2214 | 2232 | @support.requires_working_socket() | |
| 2215 | 2233 | @threading_helper.requires_working_threading() | |
| 2216 | 2234 | class HTTPHandlerTest(BaseTest): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + :class:`logging.handlers.SysLogHandler` no longer fails | ||
| 2 | + if the address cannot be resolved when the handler is created. | ||
| 3 | + The address is resolved again when a record is emitted. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments