Skip to content
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

bpo-38615: Add timeout parameter for IMAP4 and IMAP4_SSL constructor #17203

Merged
merged 12 commits into from
Jan 7, 2020

Conversation

corona10
Copy link
Member

@corona10 corona10 commented Nov 17, 2019

Copy link
Member

@ericvsmith ericvsmith left a comment

Choose a reason for hiding this comment

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

Thanks for the patch. See my notes about using a default value of None. Also, tests are needed.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@corona10
Copy link
Member Author

@ericvsmith

I have made the requested changes; please review again

  • Update default timeout parameter into None
  • Add a unit test for the timeout parameter

"All arguments to commands are converted to strings," is no longer correct and needs to be fixed.

Since the PR affected constructor but the document talk about commands,
so, I don't know the history of the command arguments.
Is there any suggestion to change or what about creating an issue on bugs.python.org?

@bedevere-bot
Copy link

Thanks for making the requested changes!

@ericvsmith: please review the changes made to this pull request.

Copy link
Member

@ericvsmith ericvsmith left a comment

Choose a reason for hiding this comment

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

We'll need to find some way for testing the actual functionality of timing out. Maybe poplib or smtplib or something similar has some code that can be used?

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@corona10
Copy link
Member Author

corona10 commented Nov 19, 2019

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@ericvsmith: please review the changes made to this pull request.

@corona10
Copy link
Member Author

@ericvsmith @python/email-team

if you don't mind, Can I get the review for this PR?
Thank you for your precious time :)

@corona10 corona10 requested a review from maxking December 8, 2019 12:55
@corona10
Copy link
Member Author

corona10 commented Dec 8, 2019

@maxking Would you like to take a look at this PR if you don`t mind?

@bedevere-bot
Copy link

Thanks for making the requested changes!

@maxking, @vstinner, @ericvsmith: please review the changes made to this pull request.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the update (reject timeout=0).

@vstinner
Copy link
Member

vstinner commented Jan 6, 2020

Hum, 2 tests failed on the macOS :-( @corona10: Can you have a look?

======================================================================
ERROR: test_imaplib_timeout_test (test.test_imaplib.NewIMAPSSLTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/test/test_imaplib.py", line 446, in test_imaplib_timeout_test
    client = self.imap_class("localhost", addr, timeout=support.LOOPBACK_TIMEOUT)
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/imaplib.py", line 1307, in __init__
    IMAP4.__init__(self, host, port, timeout)
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/imaplib.py", line 201, in __init__
    self.open(host, port, timeout)
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/imaplib.py", line 1320, in open
    IMAP4.open(self, host, port, timeout)
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/imaplib.py", line 311, in open
    self.sock = self._create_socket(timeout)
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/imaplib.py", line 1311, in _create_socket
    return self.ssl_context.wrap_socket(sock,
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
socket.timeout: _ssl.c:1091: The handshake operation timed out


======================================================================
ERROR: test_imaplib_timeout_test (test.test_imaplib.NewIMAPTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/test/test_imaplib.py", line 446, in test_imaplib_timeout_test
    client = self.imap_class("localhost", addr, timeout=support.LOOPBACK_TIMEOUT)
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/imaplib.py", line 204, in __init__
    self._connect()
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/imaplib.py", line 246, in _connect
    self.welcome = self._get_response()
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/imaplib.py", line 1058, in _get_response
    resp = self._get_line()
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/imaplib.py", line 1166, in _get_line
    line = self.readline()
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/imaplib.py", line 322, in readline
    line = self.file.readline(_MAXLINE + 1)
  File "/Users/runner/runners/2.163.1/work/cpython/cpython/Lib/socket.py", line 704, in readinto
    return self._sock.recv_into(b)
socket.timeout: timed out

@corona10
Copy link
Member Author

corona10 commented Jan 7, 2020

@vstinner This is very strange, what was happened between 3fbe5fa and a8dee3a

@corona10
Copy link
Member Author

corona10 commented Jan 7, 2020

I am able to reproduce in my local machine. I will take look at it.

@corona10
Copy link
Member Author

corona10 commented Jan 7, 2020

@vstinner I have made the requested changes; please review again

This is a potential issue.

  • When we test client, we don't wait until the server is ready.
  • Current tests are tested with timeout=None, so they wait until the server is ready.
  • So I relocation timeout test order: c903dec (None -> LOOPBACK_TIMEOUT -> 0)

@bedevere-bot
Copy link

Thanks for making the requested changes!

@vstinner, @ericvsmith, @maxking: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from vstinner January 7, 2020 04:43
@vstinner vstinner merged commit 13a7ee8 into python:master Jan 7, 2020
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jan 31, 2020
…ythonGH-17203)

imaplib.IMAP4 and imaplib.IMAP4_SSL now have an 
optional *timeout* parameter for their constructors.
Also, the imaplib.IMAP4.open() method now has an optional *timeout* parameter
with this change. The overridden methods of imaplib.IMAP4_SSL and
imaplib.IMAP4_stream were applied to this change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants