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-36123:race condition in test_socket #12053

Merged
merged 3 commits into from
Feb 26, 2019

Conversation

nanjekyejoannah
Copy link
Contributor

@nanjekyejoannah nanjekyejoannah commented Feb 26, 2019

I have set timeout once the socket is created rather than setting timeout on the
connection.

cc @vstinner

https://bugs.python.org/issue36123

@bedevere-bot bedevere-bot added tests Tests in the Lib/test dir awaiting review labels Feb 26, 2019
@nanjekyejoannah nanjekyejoannah changed the title Remove race condition in test_socket bpo-36123:race condition in test_socket Feb 26, 2019
@@ -0,0 +1,2 @@
timeout is now set once the socket is created in :_testWithTimeoutTriggeredSend(self) rather than on the
Copy link
Member

Choose a reason for hiding this comment

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

In your NEWS entry, it's unclear why you need this change. I prefer to explicit say that you fix a race condition, and mention the test name from the start. Moreover, "_testWithTimeoutTriggeredSend" is the private method, whereas testWithTimeoutTriggeredSend() is the public test name.

Fix test_socket.testWithTimeoutTriggeredSend() race condition: timeout is now set once the socket is created in rather than on the connection.

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

Copy link
Contributor

@eamanu eamanu left a comment

Choose a reason for hiding this comment

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

LGTM. This have sense, but I don't know how to test it.

@vstinner
Copy link
Member

I'm able to reproduce the race condition using:

diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 7c5167d850..3f749b95f9 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -5577,7 +5577,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest):
     FILESIZE = (10 * 1024 * 1024)  # 10 MiB
     BUFSIZE = 8192
     FILEDATA = b""
-    TIMEOUT = 2
+    TIMEOUT = 0.001
 
     @classmethod
     def setUpClass(cls):

I'm not sure that the PR is enough. I suggest to also use a longer timeout on accept(). @nanjekyejoannah: can you please also include the following change in your PR?

diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 7c5167d850..e127838d96 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -5603,7 +5603,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest):
         support.unlink(support.TESTFN)
 
     def accept_conn(self):
-        self.serv.settimeout(self.TIMEOUT)
+        self.serv.settimeout(MAIN_TIMEOUT)
         conn, addr = self.serv.accept()
         conn.settimeout(self.TIMEOUT)
         self.addCleanup(conn.close)

MAIN_TIMEOUT is 60 seconds, whereas TIMEOUT is "only" 2 seconds. The FreeBSD buildbot is really slow, so a longer timeout can help.

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.

@miss-islington
Copy link
Contributor

Thanks @nanjekyejoannah for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 26, 2019
…ion (pythonGH-12053)

Use longer timeout for accept() in the server and block on accept in the client.
The client now only sets the timeout once the socket is connected.
(cherry picked from commit 53b9e1a)

Co-authored-by: Joannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com>
@bedevere-bot
Copy link

GH-12056 is a backport of this pull request to the 3.7 branch.

miss-islington added a commit that referenced this pull request Feb 26, 2019
…ion (GH-12053)

Use longer timeout for accept() in the server and block on accept in the client.
The client now only sets the timeout once the socket is connected.
(cherry picked from commit 53b9e1a)

Co-authored-by: Joannah Nanjekye <33177550+nanjekyejoannah@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants