-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-30378: Fix the problem that SysLogHandler can't handle IPv6 addresses #1676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@zhangyangyu, thanks for your PR! By analyzing the history of the files in this pull request, we identified @vsajip, @tiran and @benjaminp to be potential reviewers. |
Lib/logging/handlers.py
Outdated
@@ -812,6 +812,7 @@ def __init__(self, address=('localhost', SYSLOG_UDP_PORT), | |||
self.address = address | |||
self.facility = facility | |||
self.socktype = socktype | |||
self.formatter = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be needed, as it is done in the base class __init__()
, which is invoked on line 810.
Lib/logging/handlers.py
Outdated
host, port = address | ||
err = None | ||
for res in socket.getaddrinfo(host, port, 0, socktype): | ||
af, socktype, proto, cannonname, sa = res |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The canonical name isn't used, so could use _
to bind it. Otherwise, use canonical
as the name to bind to - cannonname
is wrong.
Lib/logging/handlers.py
Outdated
sock.connect(sa) | ||
self.socket = sock | ||
self.socktype = socktype | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO break
is better here.
Lib/logging/handlers.py
Outdated
self.socket = sock | ||
self.socktype = socktype | ||
return | ||
except OSError as _: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just use a finally
clause to close the socket, and let the error propagate naturally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly speaking, I copied most logic from socket.create_connection()
. But I don't understand how to use finally
here. We only need to close the socket when socket.connect()
fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, you're right. My mistake.
Lib/logging/handlers.py
Outdated
sock.close() | ||
if err is not None: | ||
raise err | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this else
really belong to the for
loop rather than the if
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use return
, there's no difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you referring to my other comment? If so, I agree that return
is equivalent to break
functionally, but I prefer to use break
because then in future code can be added after the for
loop if needed. I generally prefer to avoid return
in the middle of functions when it's easy to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. But we can't make else
belong to the for
loop here. If all the results are tried and fail, we could also go into the else
branch and give wrong message. I reformat the code a bit, please see it's okay or not. :-)
@@ -327,6 +327,9 @@ Extension Modules | |||
Library | |||
------- | |||
|
|||
- bpo-30378: Fix the problem that logging.handlers.SysLogHandler cannot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure having this in the patch is a good idea - may cause unnecessary merge conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, NEWS now is the main source of merge backport conflicts, but we need to log what happened. :-(
Notice the merge conflict with Misc/NEWS. Suggest you remove this from the patch - it can always be added in a separate patch which will not require careful review, since it won't have any code. |
@vsajip , I'll take care of it. I have solved such conflicts many times. So does the code change LGTY now and I can merge it? |
Is it possible to have it favour the IPv4 addresses that are resolved? That will still allow us to use IPv6 but keep the same behaviour as before. |
@coldeasy Please open an issue on https://bugs.python.org to discuss it. |
No description provided.