python / cpython

The Python programming language
https://www.python.org/
Other
60.06k stars 29.09k forks source link

GH-118095: Make invalidating and clearing executors memory safe #118459

Closed markshannon closed 2 weeks ago

markshannon commented 2 weeks ago

This fixes a crash when an executor forms a reference cycle with itself. This bug has been present for a while, but was only exposed by https://github.com/python/cpython/pull/118420.

Also fixes another latent bug in _Py_Executors_InvalidateDependency, where clearing one executor could clear another leaving the iteration variable pointing to freed memory.

The ~three main changes~ amongst the main changes are:

markshannon commented 2 weeks ago

There are no new tests as I can't see a way to test this, especially the out-of-memory checks.

markshannon commented 2 weeks ago

The 32 bit Windows Jit build failure is probably unrelated as it has been flaky lately.

bedevere-bot commented 2 weeks ago

:warning::warning::warning: Buildbot failure :warning::warning::warning:

Hi! The buildbot ARM64 MacOS M1 Refleaks NoGIL 3.x has failed when building commit f6fab21721c8aedc5dca97dbeb6292a067c19bf1.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/1368/builds/882) and take a look at the build logs.
  4. Check if the failure is related to this commit (f6fab21721c8aedc5dca97dbeb6292a067c19bf1) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/1368/builds/882

Failed tests:

Failed subtests:

Summary of the results of the build (if available):

==

Click to see traceback logs ```python-traceback Traceback (most recent call last): File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/test/test_concurrent_futures/executor.py", line 131, in test_free_reference self.assertIsNone(wr()) ~~~~~~~~~~~~~~~~~^^^^^^ AssertionError: is not None Traceback (most recent call last): File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/test/test_threading.py", line 2035, in test_interrupt_main_subthread t.start() ~~~~~~~^^ File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/threading.py", line 977, in start self._started.wait() # Will set ident and native_id ~~~~~~~~~~~~~~~~~~^^ File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/threading.py", line 656, in wait with self._cond: ...<3 lines>... return signaled File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/threading.py", line 307, in __exit__ return self._lock.__exit__(*args) ~~~~~~~~~~~~~~~~~~~^^^^^^^ RuntimeError: release unlocked lock Traceback (most recent call last): File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/threading.py", line 659, in wait signaled = self._cond.wait(timeout) ~~~~~~~~~~~~~~~^^^^^^^^^ File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/threading.py", line 368, in wait self._acquire_restore(saved_state) ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/threading.py", line 315, in _acquire_restore def _acquire_restore(self, x): KeyboardInterrupt ```