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

gh-84532: Reopen the socket in SocketHandler.send() when sending fails by serhiy-storchaka · Pull Request #154540 · python/cpython · GitHub

Repository navigation

gh-84532: Reopen the socket in SocketHandler.send() when sending fails - #154540

Open
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:fix-sockethandler-reconnect
Open

serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:fix-sockethandler-reconnect

Conversation

Copy link
Copy Markdown
Member

SocketHandler.send() dropped the record whose sending failed and reconnected only on the next record, so after the connection was closed (for example after an idle timeout) it lost more records than necessary.

It now reopens the socket and sends the record again, like SysLogHandler.emit() has done for the Unix socket since 2.5.

This does not make SocketHandler lossless over TCP: the first record sent after the connection is closed still succeeds locally and is lost when the reset arrives, which cannot be detected. But it stops dropping the following record, whose send actually fails.

🤖 Generated with Claude Code

…g fails

It dropped the record whose send failed and reconnected only on the next
record.  Now it reopens the socket and sends the record again.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The test left the server-side connections unclosed, which regrtest reported
as an altered environment (ResourceWarning: unclosed socket).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread Lib/logging/handlers.py
# retry time yet, or because we have reached the retry time
# and retried, but are still unable to connect.
if self.sock is None:
return

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

How about a break here? I prefer not to do early returns - e.g. if we were ever to add something after the for statement, we wouldn't need to revisit this line.

Comment thread Lib/logging/handlers.py
try:
self.sock.sendall(s)
except OSError: #pragma: no cover
return

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

As comment above.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL