Hi,
In the current implementation of the SysLogHandler class from the logging.handlers module, if the specified address does not respond or is unreachable, the createSocket method may block indefinitely. This is problematic because there is no way to set a socket timeout during the connection's creation without overriding the entire createSocket method.
The only way to add timeout is to override the whole createSocket method (if I use super().createSocket() it will get stuck on this line)
If I remember correct, the SysLog is based on the UDP protocol. I'm sure the timeout is useful for UDP
Syslog uses both UDP and TCP. A timeout is crucial to avoid blocking the process if the service is unreachable or slow to respond. In my case, I'm using TCP, and the server is unreachable, causing my process to be blocked indefinitely. Adding timeout support to SysLogHandler would allow the application to fail gracefully in such scenarios, instead of hanging due to network issues.
Before starting the implementation, I wonder whether this should count as a bug fix or not (and whether there is another way to fix it). So let's ask @vsajip first.
Activity
Zheaoli commented on Nov 4, 2024
If I remember correct, the SysLog is based on the UDP protocol. I'm sure the timeout is useful for UDP
hodamarr commented on Nov 4, 2024
Syslog uses both UDP and TCP. A timeout is crucial to avoid blocking the process if the service is unreachable or slow to respond. In my case, I'm using TCP, and the server is unreachable, causing my process to be blocked indefinitely. Adding timeout support to SysLogHandler would allow the application to fail gracefully in such scenarios, instead of hanging due to network issues.
hodamarr commented on Nov 10, 2024
Hey @picnixz I can take care of this—could you assign me to it?
picnixz commented on Nov 10, 2024
Before starting the implementation, I wonder whether this should count as a bug fix or not (and whether there is another way to fix it). So let's ask @vsajip first.
hodamarr commented on Nov 10, 2024
Sure, let me know when its okay to open a pull request.
@vsajip @picnixz
vsajip commented on Nov 10, 2024
Yes, this seems a reasonable feature to add. You're welcome to submit a PR with docs/tests.
pythongh-126400: Add TCP socket timeout to SysLogHandler
pythongh-126400: Add TCP socket timeout to SysLogHandler
gh-126400: Add TCP socket timeout to SysLogHandler to prevent blocking (
pythongh-126400: Add TCP socket timeout to SysLogHandler to prevent b…