-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
SMTPServer of smptd does not support binding to an IPv6 address #58963
Comments
The SMTPServer class of the smtpd module creates a server socket with the IPv4 socket.AF_INET address family hardcoded, and this prevents it from later binding to an IPv6 local address. This occurs on line 282 of smtpd.py for the Python 2.7 branch: And on line 435 of smtpd for the Python 3.2 branch ( Lib/smtpd.py:435 ): One IPv4/IPv6 agnostic solution is to look up provided local address with getaddrinfo(), and use one of the result's address family, socket type and address tuple for create_socket() and bind() at those lines: ... |
Agreed. The only problem I see is that unit tests rely on a mock socket object and should be rewritten by using an actual socket. |
I don't think it is necessary to rewrite the existing tests, just add some that test the socket functionality. |
Unfortunately unit tests overwrite the original smtpd.socket module object with test.mock_socket [1] and the latter one doesn't expose socket.getaddrinfo(). [1] http://hg.python.org/cpython/file/d937b527b76e/Lib/test/test_smtpd.py#l54 |
Well, that should be fixed anyway (a cleanup added that restores the original value). Then a new TestCase can test the socket stuff. |
I was going to work on bpo-3461 where IPv6-tests are missing for smtplib and stumbled over this bug. I would be willing to work on this, since it's quiet clear what needs to be done to me: implement what (vsergeev) suggested and write tests (which includes fixing design flaws in current ones). It may be a good idea to teach mouckup_socket some IPv6, since it's needed for test_smtpd and test_smtplib, but IMHO that can be done as a extra task / will be easy after doing the above. |
The cleaning up of smtpd.socket was already implemented, so there was nothing to do there. What I did:
|
I added some review comments. Since this is a new feature, the patch also needs a 'versionchanged' that indicates that ipv6 support was added. |
I applied your suggestions. |
When I run the modified test suite on a machine regrtest tells me that the test modified the environment, specifically the asyncore.socket_map. Presumably there is some missing cleanup logic. |
Fixed it. |
New changeset 1efbc86a200a by R David Murray in branch 'default': |
Thanks, Milan. I had to fix a couple things: you had left the "refactored" methods on the SMTPDServerTest, and somehow your new TestFamilyDetection class got indented under SMTPDServerTest in the new version of the patch. (I also had to update it to compensate for the decode_data patch, which copy-and-pasted the DummyServer calling bugs you fixed in the other tests...) |
Hmm. Looks like the IPv6 support is making the FreeBSD and and OSX buildbots unhappy :(. |
New changeset d8e0fca7cbe3 by R David Murray in branch 'default': |
New changeset 9b0d58b0c712 by R David Murray in branch 'default': |
OK, I think this is fixed. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: