Skip to content

Fix RuntimeError on dictionary size change during iteration#4891

Open
perhapsmaple wants to merge 1 commit intoopen-telemetry:mainfrom
perhapsmaple:dict-size-change
Open

Fix RuntimeError on dictionary size change during iteration#4891
perhapsmaple wants to merge 1 commit intoopen-telemetry:mainfrom
perhapsmaple:dict-size-change

Conversation

@perhapsmaple
Copy link

Description

Fixes #4785

Create a stable snapshot of the dictionary items before iteration. This prevents the RuntimeError even if the dictionary is modified during iteration.

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Runs collection in one thread while registering new instruments in multiple threads

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Signed-off-by: Harish <140232061+perhapsmaple@users.noreply.github.com>
@perhapsmaple perhapsmaple requested a review from a team as a code owner February 1, 2026 11:56
Copy link
Contributor

@xrmx xrmx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add a testcase to check we don't regress?

@xrmx xrmx moved this to Easy to review / merge / close in @xrmx's Python PR digest Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Easy to review / merge / close

Development

Successfully merging this pull request may close these issues.

[metrics] dictionary changed size during iteration

2 participants