Fix RuntimeError in get_block_device_mapping - #10185
Open
jeblair wants to merge 1 commit into
Open
Conversation
In a multi-threaded situation, the block_device_mapping dictionary
can change in one thread while another thread is iterating over it
using get_block_device_mapping. Fix that by returning a list
instead of an iterator (as we do for the network_interfaces
property below).
Last few lines of a sample traceback:
File "/home/zuul/src/opendev.org/zuul/zuul/.nox/tests-3-14/lib/python3.14/site-packages/moto/core/serialize.py", line 1282, in __call__
value = get_value(obj, possible_key, MISSING)
File "/home/zuul/src/opendev.org/zuul/zuul/.nox/tests-3-14/lib/python3.14/site-packages/moto/core/utils.py", line 483, in get_value
return _get_value_for_key(obj, key, default)
File "/home/zuul/src/opendev.org/zuul/zuul/.nox/tests-3-14/lib/python3.14/site-packages/moto/core/utils.py", line 496, in _get_value_for_key
return getattr(obj, str(key), default)
File "/home/zuul/src/opendev.org/zuul/zuul/.nox/tests-3-14/lib/python3.14/site-packages/moto/ec2/models/instances.py", line 334, in block_device_mappings
for device_name, block in self.get_block_device_mapping:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: dictionary changed size during iteration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In a multi-threaded situation, the block_device_mapping dictionary can change in one thread while another thread is iterating over it using get_block_device_mapping. Fix that by returning a list instead of an iterator (as we do for the network_interfaces property below).
Last few lines of a sample traceback: