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

Support socket timeout in SysLogHandler to prevent indefinite blocking on socket creation · Issue #126400 · python/cpython · GitHub

Repository navigation

Support socket timeout in SysLogHandler to prevent indefinite blocking on socket creation #126400

Closed

Description

Feature or enhancement

Proposal:

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)

my suggestion:

class SysLogHandler(logging.Handler):
    def __init__(self, address=('localhost', SYSLOG_UDP_PORT), 
                 facility=LOG_USER, socktype=None, timeout=None):
        # Existing initialization
        self.timeout = timeout  # New timeout parameter
        self.createSocket()
    
    def createSocket(self):
        # Existing code ....
        try:
            sock = socket.socket(af, socktype, proto)
            **if self.timeout:
                     sock.setttimeout(self.timeout)**
            # Existing code ........

Thanks

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. Zheaoli commented on Nov 4, 2024

    Contributor

    If I remember correct, the SysLog is based on the UDP protocol. I'm sure the timeout is useful for UDP

  2. hodamarr commented on Nov 4, 2024

    ContributorAuthor

    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.

  3. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 6, 2024
  4. hodamarr commented on Nov 10, 2024

    ContributorAuthor

    Hey @picnixz I can take care of this—could you assign me to it?

  5. picnixz commented on Nov 10, 2024

    Member

    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.

  6. hodamarr commented on Nov 10, 2024

    ContributorAuthor

    Sure, let me know when its okay to open a pull request.
    @vsajip @picnixz

  7. vsajip commented on Nov 10, 2024

    Member

    Yes, this seems a reasonable feature to add. You're welcome to submit a PR with docs/tests.

  8. added a commit that references this issue on Nov 12, 2024
  9. added a commit that references this issue on Nov 30, 2024
  10. added a commit that references this issue on Jan 29, 2025
  11. added a commit that references this issue on Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


Back | FazBrowse Home | New Git URL