Skip to content

bpo-33735: Fix test_multiprocessing random failure #8059

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 1 commit into from
Jul 3, 2018
Merged

bpo-33735: Fix test_multiprocessing random failure #8059

merged 1 commit into from
Jul 3, 2018

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jul 3, 2018

When hunting for memory leaks using -R 3:3, test_imap_unordered() of
test_multiprocessing leaks randomly a few memory blocks. It is a
false alarm: when testing using -R 3:20 for example, no leak is
detected.

Modify test_imap_unordered() to be closer to test_imap():

  • Only test 10 numbers instead of 100: it's a pool of 4 processes, so
    10 is enough to test at least one number per process
  • Use chunksize=100 instead of chunksize=53 to mimick test_imap()

https://bugs.python.org/issue33735

When hunting for memory leaks using -R 3:3, test_imap_unordered() of
test_multiprocessing leaks randomly a few memory blocks. It is a
false alarm: when testing using -R 3:20 for example, no leak is
detected.

Modify test_imap_unordered() to be closer to test_imap():

* Only test 10 numbers instead of 100: it's a pool of 4 processes, so
  10 is enough to test at least one number per process
* Use chunksize=100 instead of chunksize=53 to mimick test_imap()
@vstinner
Copy link
Member Author

vstinner commented Jul 3, 2018

I validated on my laptop that the change fixes the false alarm.

I modified locally regrtest to make it stricter:

diff --git a/Lib/test/libregrtest/refleak.py b/Lib/test/libregrtest/refleak.py
index 6724488fcf..a3c50e21e0 100644
--- a/Lib/test/libregrtest/refleak.py
+++ b/Lib/test/libregrtest/refleak.py
@@ -101,7 +101,7 @@ def dash_R(the_module, test, indirect_test, huntrleaks):
     failed = False
     for deltas, item_name, checker in [
         (rc_deltas, 'references', check_rc_deltas),
-        (alloc_deltas, 'memory blocks', check_rc_deltas),
+        (alloc_deltas, 'memory blocks', check_fd_deltas),
         (fd_deltas, 'file descriptors', check_fd_deltas)
     ]:
         # ignore warmup runs

On master, I can easily reproduce the issue on my idle laptop:

$ ./python -m test test_multiprocessing_spawn -m test.test_multiprocessing_spawn.WithProcessesTestPool.test_imap_unordered -R 3:20
Run tests sequentially
0:00:00 load avg: 0.78 [1/1] test_multiprocessing_spawn
beginning 23 repetitions
12345678901234567890123
.......................
test_multiprocessing_spawn leaked [5, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] memory blocks, sum=8
test_multiprocessing_spawn failed

== Tests result: FAILURE ==

1 test failed:
    test_multiprocessing_spawn

Total duration: 11 sec 112 ms
Tests result: FAILURE

With the change, the bug goes away:

vstinner@apu$ ./python -m test test_multiprocessing_spawn -m test.test_multiprocessing_spawn.WithProcessesTestPool.test_imap_unordered -R 3:20
Run tests sequentially
0:00:00 load avg: 0.92 [1/1] test_multiprocessing_spawn
beginning 23 repetitions
12345678901234567890123
.......................
test_multiprocessing_spawn leaked [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] memory blocks, sum=1
test_multiprocessing_spawn failed

== Tests result: FAILURE ==

1 test failed:
    test_multiprocessing_spawn

Total duration: 9 sec 967 ms
Tests result: FAILURE

The Refleak buildbots use -R 3:3, so only the first 3 numbers matter. Without the change, the first 3 numbers are non-zero, whereas they only one is non-zero with the change.

@vstinner
Copy link
Member Author

vstinner commented Jul 3, 2018

I also validated on the Gentoo Refleak that the change fixes the false alarm.

master branch: 2 failures on 5 runs.

pydev@stormageddon ~/cpython $ ./python -m test test_multiprocessing_spawn -m test.test_multiprocessing_spawn.WithProcessesTestPool.test_imap_unordered -R 3:3
Run tests sequentially
0:00:00 load avg: 0.41 [1/1] test_multiprocessing_spawn
beginning 6 repetitions
123456
......
test_multiprocessing_spawn leaked [2, 2, 1] memory blocks, sum=5
test_multiprocessing_spawn failed

== Tests result: FAILURE ==

1 test failed:
    test_multiprocessing_spawn

Total duration: 6 sec 539 ms
Tests result: FAILURE

With the change: 0 failure on 5 runs.

I also ran the following command with the change:

pydev@stormageddon ~/cpython $ ./python -m test test_multiprocessing_spawn -m test.test_multiprocessing_spawn.WithProcessesTestPool.test_imap_unordered -R 3:3 -F
Run tests sequentially
0:00:00 load avg: 2.81 [  1] test_multiprocessing_spawn
beginning 6 repetitions
123456
......
(...)
0:02:59 load avg: 5.17 [ 25] test_multiprocessing_spawn
beginning 6 repetitions
123456
......
0:03:09 load avg: 5.45 [ 26] test_multiprocessing_spawn
beginning 6 repetitions
123456
^C
== Tests result: INTERRUPTED ==

Test suite interrupted by signal SIGINT.
0 tests omitted:


25 tests OK.

Total duration: 3 min 10 sec
Tests result: INTERRUPTED

I interrupted the test after 25 success runs.

@vstinner vstinner merged commit 23401fb into python:master Jul 3, 2018
@miss-islington
Copy link
Contributor

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

@vstinner vstinner deleted the mp_imap_unordered branch July 3, 2018 11:20
@bedevere-bot
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 3, 2018
When hunting memory leaks using -R 3:3, test_imap_unordered() of
test_multiprocessing leaks randomly a few memory blocks. It is a
false alarm: when testing using -R 3:20 for example, no leak is
detected.

Modify test_imap_unordered() to be closer to test_imap():

* Only test 10 numbers instead of 1000: it's a pool of 4 processes, so
  10 is enough to test at least one number per process
* Use chunksize=100 instead of chunksize=53 to mimick test_imap()
(cherry picked from commit 23401fb)

Co-authored-by: Victor Stinner <[email protected]>
@miss-islington
Copy link
Contributor

Sorry, @vstinner, I could not cleanly backport this to 2.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 23401fb960bb94e6ea62d2999527968d53d3fc65 2.7

@bedevere-bot
Copy link

GH-8061 is a backport of this pull request to the 2.7 branch.

@bedevere-bot
Copy link

GH-8062 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 3, 2018
When hunting memory leaks using -R 3:3, test_imap_unordered() of
test_multiprocessing leaks randomly a few memory blocks. It is a
false alarm: when testing using -R 3:20 for example, no leak is
detected.

Modify test_imap_unordered() to be closer to test_imap():

* Only test 10 numbers instead of 1000: it's a pool of 4 processes, so
  10 is enough to test at least one number per process
* Use chunksize=100 instead of chunksize=53 to mimick test_imap()
(cherry picked from commit 23401fb)

Co-authored-by: Victor Stinner <[email protected]>
miss-islington added a commit that referenced this pull request Jul 3, 2018
When hunting memory leaks using -R 3:3, test_imap_unordered() of
test_multiprocessing leaks randomly a few memory blocks. It is a
false alarm: when testing using -R 3:20 for example, no leak is
detected.

Modify test_imap_unordered() to be closer to test_imap():

* Only test 10 numbers instead of 1000: it's a pool of 4 processes, so
  10 is enough to test at least one number per process
* Use chunksize=100 instead of chunksize=53 to mimick test_imap()
(cherry picked from commit 23401fb)

Co-authored-by: Victor Stinner <[email protected]>
vstinner added a commit that referenced this pull request Jul 3, 2018
When hunting memory leaks using -R 3:3, test_imap_unordered() of
test_multiprocessing leaks randomly a few memory blocks. It is a
false alarm: when testing using -R 3:20 for example, no leak is
detected.

Modify test_imap_unordered() to be closer to test_imap():

* Only test 10 numbers instead of 1000: it's a pool of 4 processes, so
  10 is enough to test at least one number per process
* Use chunksize=100 instead of chunksize=53 to mimick test_imap()

(cherry picked from commit 23401fb)
miss-islington added a commit that referenced this pull request Jul 3, 2018
When hunting memory leaks using -R 3:3, test_imap_unordered() of
test_multiprocessing leaks randomly a few memory blocks. It is a
false alarm: when testing using -R 3:20 for example, no leak is
detected.

Modify test_imap_unordered() to be closer to test_imap():

* Only test 10 numbers instead of 1000: it's a pool of 4 processes, so
  10 is enough to test at least one number per process
* Use chunksize=100 instead of chunksize=53 to mimick test_imap()
(cherry picked from commit 23401fb)

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants