Skip to content

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

Merged
merged 7 commits into from
Jun 1, 2017

Conversation

zhangyangyu
Copy link
Member

No description provided.

@mention-bot
Copy link

@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.

@@ -812,6 +812,7 @@ def __init__(self, address=('localhost', SYSLOG_UDP_PORT),
self.address = address
self.facility = facility
self.socktype = socktype
self.formatter = None
Copy link
Member

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.

host, port = address
err = None
for res in socket.getaddrinfo(host, port, 0, socktype):
af, socktype, proto, cannonname, sa = res
Copy link
Member

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.

sock.connect(sa)
self.socket = sock
self.socktype = socktype
return
Copy link
Member

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.

self.socket = sock
self.socktype = socktype
return
except OSError as _:
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

sock.close()
if err is not None:
raise err
else:
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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
Copy link
Member

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.

Copy link
Member Author

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. :-(

@vsajip vsajip self-assigned this May 20, 2017
@vsajip
Copy link
Member

vsajip commented May 29, 2017

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.

@zhangyangyu
Copy link
Member Author

@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?

@zhangyangyu zhangyangyu merged commit 0b4b57d into python:master Jun 1, 2017
@zhangyangyu zhangyangyu deleted the bpo-30378 branch June 1, 2017 13:12
zhangyangyu added a commit to zhangyangyu/cpython that referenced this pull request Jun 1, 2017
zhangyangyu added a commit to zhangyangyu/cpython that referenced this pull request Jun 1, 2017
@zhangyangyu zhangyangyu added type-bug An unexpected behavior, bug, or error and removed needs backport to 2.7 labels Jun 1, 2017
@coldeasy
Copy link

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.

@zhangyangyu
Copy link
Member Author

zhangyangyu commented Jul 17, 2018

@coldeasy Please open an issue on https://bugs.python.org to discuss it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants