mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-126400: Add TCP socket timeout to SysLogHandler to prevent blocking (GH-126716)
Co-authored-by: Vinay Sajip <vinay_sajip@yahoo.co.uk>
This commit is contained in:
parent
002c4e2982
commit
fdcedfd3cf
4 changed files with 27 additions and 2 deletions
|
@ -855,7 +855,7 @@ class SysLogHandler(logging.Handler):
|
|||
}
|
||||
|
||||
def __init__(self, address=('localhost', SYSLOG_UDP_PORT),
|
||||
facility=LOG_USER, socktype=None):
|
||||
facility=LOG_USER, socktype=None, timeout=None):
|
||||
"""
|
||||
Initialize a handler.
|
||||
|
||||
|
@ -872,6 +872,7 @@ class SysLogHandler(logging.Handler):
|
|||
self.address = address
|
||||
self.facility = facility
|
||||
self.socktype = socktype
|
||||
self.timeout = timeout
|
||||
self.socket = None
|
||||
self.createSocket()
|
||||
|
||||
|
@ -933,6 +934,8 @@ class SysLogHandler(logging.Handler):
|
|||
err = sock = None
|
||||
try:
|
||||
sock = socket.socket(af, socktype, proto)
|
||||
if self.timeout:
|
||||
sock.settimeout(self.timeout)
|
||||
if socktype == socket.SOCK_STREAM:
|
||||
sock.connect(sa)
|
||||
break
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue