Skip to content

[Test] Fix flaky test_complex_replay_buffer_configuration - #4718

Open
ankit373 wants to merge 1 commit into
pytorch:mainfrom
ankit373:fix/flaky-complex-replay-buffer-config
Open

ankit373 wants to merge 1 commit into
pytorch:mainfrom
ankit373:fix/flaky-complex-replay-buffer-config

Conversation

@ankit373

Copy link
Copy Markdown

Description

fixes the cpu flake test/test_configs.py::TestDataConfigs::test_complex_replay_buffer_configuration from the flaky report. the cuda dreamer test in the same report is not touched here.

the test itself is fine. it fails from a gc side effect:

  • test_configs.py sets pytestmark = pytest.mark.filterwarnings("error").
  • a replay buffer and its storage point at each other (storage.attach(buffer)), so a dropped buffer is freed by the cyclic gc, not by refcount. its storage and writer hold mp.Value semaphores.
  • if the gc runs while a new semaphore is being registered with the multiprocessing resource tracker (the storage in this test creates one), the old semaphore's finalizer calls resource_tracker.unregister inside the tracker's own lock. cpython refuses the reentrant call and emits UserWarning: ResourceTracker called reentrantly for resource cleanup ... might leak.
  • the error filter turns that into an unraisable exception, and pytest fails whatever test is running. the ci log matches exactly: ExceptionGroup: multiple unraisable exception warnings (6 sub-exceptions), each one ReentrantCallError -> that UserWarning (e.g. tests-cpu-mid (3.12, bulk), run 42443177736).

the fix ignores only that warning in the module. every other warning still fails the test (checked that a plain UserWarning still errors under the new pytestmark).

Motivation and Context

Fixes #4480 (only the test_complex_replay_buffer_configuration part)

flake rate, macos arm64, python 3.12.13, torch 2.15.0 cpu, tensordict 0.15.5, pytest 9.2.0, hydra-core 1.3.8 (same pytest/hydra as ci):

run before after
target test x3000, with a small plugin that leaves buffers in cycles and lowers the gc threshold 10 failed / 3000 0 / 3000
whole TestDataConfigs class --count 300 (9900 runs) 43 failed / 9900 0 / 9900

all "before" failures had the same ReentrantCallError / ResourceTracker called reentrantly signature as ci. the full test_configs.py run has the same set of local failures (missing optional deps) before and after.

side note, not changed here: the storage -> buffer strong ref in Storage.attach is what keeps buffers alive until the cyclic gc. a weakref there would let buffers be freed right away, but it touches pickling and sharing, so it felt out of scope for a test fix.

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

test_configs.py turns every warning into an error. A replay buffer and
its storage reference each other, so a dropped buffer is freed by the
cyclic GC, not right away. Its storage and writer hold mp.Value
semaphores. When the GC runs while a new semaphore is being registered
with the multiprocessing resource tracker, the old semaphore's
finalizer calls back into the tracker. CPython refuses the reentrant
call and emits a UserWarning ("ResourceTracker called reentrantly").
The error filter turns that into an unraisable exception, and pytest
fails whatever test happened to be running.

Ignore that one warning in the module so the error filter keeps
catching everything else.

Signed-off-by: Ankit Jha <jhaankit373@gmail.com>
@pytorch-bot

pytorch-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/4718

Note: Links to docs will display an error until the docs builds have been completed.

⚠️ 16 Awaiting Approval

As of commit 4d3ea77 with merge base a711ef9 (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla

meta-cla Bot commented Nov 11, 2026

Copy link
Copy Markdown

Hi @ankit373!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions github-actions Bot added the Tests Incomplete or broken unit tests label Nov 11, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 11, 2026
@meta-cla

meta-cla Bot commented Nov 11, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Tests Incomplete or broken unit tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Flaky Tests] 2 flaky test(s) detected

1 participant