Skip to content

SysLogHandler closes tcp session after first message (also noted in #66006) #95891

Open
@rforrest138

Description

@rforrest138

Bug report

Python 3.10.5
While running FastAPI (Uvicorn) and the SysLogHandler. The Socket if using a TCP stream is being closed after the first message, causing all additional messages to fail stating OSError10083. In looking through the SysLogHandler code I was able to add a try/except that solved the issue by opening a new socket if the current is found to be closed.

Lines 990/991:

else:
    self.socket.sendall(msg)

I changed to:

else:
    try:
        self.socket.sendall(msg)
    except OSError:
        with socket.create_connection(self.address) as s:
            s.sendall(msg)

Your environment

Python 3.10

  • CPython versions tested on: 3.10
  • Operating system and architecture: Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions