Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Jul 18, 2018

Sometimes on Windows, test_signal.test_socket() fails on recv(1) with
BlockingIOError. The C signal handler wrote the signal number using
send() which returns 1 byte as expected, but the read end of the
socket pair doesn't get "immediately" the byte.

Configure the read end of the socket pair as blocking to wait until
we get the signal number and so fix the race condition on Windows.

Use also "with" context manager to ensure that the sockets are closed
even if the test fails.

https://bugs.python.org/issue34130

Sometimes on Windows, test_signal.test_socket() fails on recv(1) with
BlockingIOError. The C signal handler wrote the signal number using
send() which returns 1 byte as expected, but the read end of the
socket pair doesn't get "immediately" the byte.

Configure the read end of the socket pair as blocking to wait until
we get the signal number and so fix the race condition on Windows.
@vstinner
Copy link
Member Author

The first version of my PR included unrelated minor changes, I chose to revert them to make the PR much simpler to backport (it's now a single line removed).

@vstinner vstinner merged commit 99bb6df into python:master Jul 18, 2018
@vstinner vstinner deleted the signal_test_socket branch July 18, 2018 15:44
@miss-islington
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-8330 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 18, 2018
test_signal.test_socket(): On Windows, sometimes even if the C signal handler
succeed to write the signal number into the write end of the socketpair, the
test fails with a BlockingIOError on the non-blocking read.recv(1) because the
read end of the socketpair didn't receive the byte yet.

Fix the race condition on Windows by setting the read end as blocking.
(cherry picked from commit 99bb6df)

Co-authored-by: Victor Stinner <[email protected]>
vstinner added a commit that referenced this pull request Jul 18, 2018
* bpo-34130: Fix test_signal.test_socket() (GH-8326)

test_signal.test_socket(): On Windows, sometimes even if the C signal handler
succeed to write the signal number into the write end of the socketpair, the
test fails with a BlockingIOError on the non-blocking read.recv(1) because the
read end of the socketpair didn't receive the byte yet.

Fix the race condition on Windows by setting the read end as blocking.

(cherry picked from commit 99bb6df)

* bpo-34130: Fix test_signal.test_warn_on_full_buffer() (GH-8327)

On Windows, sometimes test_signal.test_warn_on_full_buffer() fails to
fill the socketpair buffer. In that case, the C signal handler
succeed to write into the socket, it doesn't log the expected send
error, and so the test fail.

On Windows, the test now uses a timeout of 50 ms to fill the
socketpair buffer to fix this race condition.

Other changes:

* Begin with large chunk size to fill the buffer to speed up the
  test.
* Add error messages to assertion errors to more easily identify
  which assertion failed.
* Don't set the read end of the socketpair as non-blocking.

(cherry picked from commit 686b4b5)
vstinner added a commit that referenced this pull request Jul 18, 2018
test_signal.test_socket(): On Windows, sometimes even if the C signal handler
succeed to write the signal number into the write end of the socketpair, the
test fails with a BlockingIOError on the non-blocking read.recv(1) because the
read end of the socketpair didn't receive the byte yet.

Fix the race condition on Windows by setting the read end as blocking.
(cherry picked from commit 99bb6df)

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants