Skip to content

test_semaphore_tracker() of test_multiprocessing_spawn fails randomly (race condition?) #75868

Closed

Description

@vstinner
BPO 31687
Nosy @ncoghlan, @vstinner, @Subler

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:

assignee = None
closed_at = <Date 2018-09-19.23:27:14.912>
created_at = <Date 2017-10-04.09:36:35.852>
labels = ['3.7', 'tests']
title = 'test_semaphore_tracker() of test_multiprocessing_spawn fails randomly (race condition?)'
updated_at = <Date 2018-09-19.23:27:14.911>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2018-09-19.23:27:14.911>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2018-09-19.23:27:14.912>
closer = 'vstinner'
components = ['Tests']
creation = <Date 2017-10-04.09:36:35.852>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 31687
keywords = []
message_count = 9.0
messages = ['303678', '306557', '307355', '307356', '310360', '310949', '320613', '321016', '325825']
nosy_count = 3.0
nosy_names = ['ncoghlan', 'vstinner', 'stevezh']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue31687'
versions = ['Python 3.6', 'Python 3.7']

Activity

  1. vstinner commented on Oct 4, 2017

    @vstinner
    MemberAuthor

    Recent example of the slow and busy (load of 8.05 with 2 CPUs) x86 Gentoo Refleaks 3.6 buildbot:

    http://buildbot.python.org/all/builders/x86%20Gentoo%20Refleaks%203.6/builds/111/steps/test/logs/stdio

    == CPU count: 2
    ...
    1:41:09 load avg: 8.05 [170/405/1] test_multiprocessing_spawn failed -- running: test_asyncio (1118 sec)
    beginning 6 repetitions
    123456
    /buildbot/buildarea/3.6.ware-gentoo-x86.refleak/build/Lib/unittest/case.py:633: ResourceWarning: unclosed file <_io.BufferedReader name=22>
      outcome.errors.clear()
    test test_multiprocessing_spawn failed -- Traceback (most recent call last):
      File "/buildbot/buildarea/3.6.ware-gentoo-x86.refleak/build/Lib/test/_test_multiprocessing.py", line 4091, in test_semaphore_tracker
        _multiprocessing.sem_unlink(name2)
    AssertionError: OSError not raised
    1:41:12 load avg: 7.97 [171/405/1] test_posixpath passed -- running: test_asyncio (1122 sec)
    beginning 6 repetitions
    123456
    ......
  2. vstinner commented on Nov 20, 2017

    @vstinner
    MemberAuthor

    Failure on x86 Gentoo Refleaks 3.6, two days ago:

    http://buildbot.python.org/all/#/builders/72/builds/41

    ======================================================================
    FAIL: test_semaphore_tracker (test.test_multiprocessing_spawn.TestSemaphoreTracker)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/buildbot/buildarea/3.6.ware-gentoo-x86.refleak/build/Lib/test/_test_multiprocessing.py", line 4161, in test_semaphore_tracker
        _multiprocessing.sem_unlink(name2)
    AssertionError: OSError not raised

    ======================================================================
    FAIL: test_sys_exit (test.test_multiprocessing_spawn.WithProcessesTestSubclassingProcess)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/buildbot/buildarea/3.6.ware-gentoo-x86.refleak/build/Lib/test/_test_multiprocessing.py", line 584, in test_sys_exit
        self.assertEqual(p.exitcode, 1)
    AssertionError: None != 1
  3. vstinner commented on Dec 1, 2017

    @vstinner
    MemberAuthor

    x86 Tiger 3.x:

    http://buildbot.python.org/all/#/builders/30/builds/260

    ======================================================================
    FAIL: test_semaphore_tracker (test.test_multiprocessing_forkserver.TestSemaphoreTracker)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/Users/db3l/buildarea/3.x.bolen-tiger/build/Lib/test/_test_multiprocessing.py", line 4380, in test_semaphore_tracker
        _multiprocessing.sem_unlink(name2)
    AssertionError: OSError not raised

    ======================================================================
    FAIL: test_forkserver_sigkill (test.test_multiprocessing_forkserver.WithProcessesTestProcess)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/Users/db3l/buildarea/3.x.bolen-tiger/build/Lib/test/_test_multiprocessing.py", line 653, in test_forkserver_sigkill
        self.check_forkserver_death(signal.SIGKILL)
      File "/Users/db3l/buildarea/3.x.bolen-tiger/build/Lib/test/_test_multiprocessing.py", line 643, in check_forkserver_death
        self.assertTrue(evt.is_set())
    AssertionError: False is not true
  4. subler commented on Dec 1, 2017

    sublermannequin
    Mannequin

    It maybe the semaphore tracker process doesn't unlink the semaphore as soon as possible when child process exit when the system is slow. Increase test case's time in the child and before assertRaises will help.

  5. vstinner commented on Jan 20, 2018

    @vstinner
    MemberAuthor

    To reproduce the issue, someone should increase the system load to make the system slower and make timeouts more likely, and change the order in which processes are run. I'm using the "stress" utility on Linux for that. But sometimes, the best stress tool... is the Python test suite, since running the full test suite in multiple processes in parallel (./python -m test -j0 -r) runs various workloads, and so sometimes trigger bugs which would be very hard to trigger othewise.

    Terminal 1: run "./python -m test -j0 -r", stress or anything else to make the system slower

    Terminal 2: run "./python -m test test_multiprocessing_fork -m test_semaphore_tracker -F -v" which runs the test in a loop until it fails.

  6. ncoghlan commented on Jan 28, 2018

    @ncoghlan
    Contributor

    A warning I'm sometimes seeing currently on successful test runs is as follows:

    ------
    /home/ncoghlan/devel/cpython/Lib/multiprocessing/semaphore_tracker.py:55: UserWarning: semaphore_tracker: process died unexpectedly, relaunching. Some semaphores might leak.
    warnings.warn('semaphore_tracker: process died unexpectedly, '
    ------

    So it may be that the system has to be under load for the test suite to notice that failure.

  7. vstinner commented on Jun 27, 2018

    @vstinner
    MemberAuthor

    See also bpo-33613.

  8. vstinner commented on Jul 4, 2018

    @vstinner
    MemberAuthor

    FAIL: test_forkserver_sigkill (test.test_multiprocessing_forkserver.WithProcessesTestProcess)

    This failure is unrelated to the semaphore tracker, so I created bpo-34040: "test_multiprocessing_forkserver: test_forkserver_sigkill() fails randomly".

  9. vstinner commented on Sep 19, 2018

    @vstinner
    MemberAuthor

    bpo-33613 and bpo-34040 have been fixed. I hope that it will be enough.

  10. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.7 (EOL)end of lifetestsTests in the Lib/test dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions