Skip to content

api: Avoid race-condition in volume-attach timeout handling#593

Open
leust wants to merge 1 commit intostable/2023.2-m3from
timeout-rm-bdm
Open

api: Avoid race-condition in volume-attach timeout handling#593
leust wants to merge 1 commit intostable/2023.2-m3from
timeout-rm-bdm

Conversation

@leust
Copy link

@leust leust commented Jan 21, 2026

When nova-api calls reserve_block_device_name RPC to nova-compute and the call times out, we try to clean up by deleting the BDM entry. However, during the timeout window a second attachment request for the same volume can come in, create a valid BDM, and progress to talking to Cinder. The original timed-out request then deletes this new valid BDM, leaving the volume in an inconsistent state.

We fix this by checking if the BDM has attachment_id set before deleting it. The attachment_id field is only populated in _check_attach_and_reserve_volume(), which we only call after the reserve_block_device_name RPC succeeds. If attachment_id is set, we know the BDM belongs to a subsequent request that has already progressed past the RPC phase, so we should not delete it.

Change-Id: I7ed649a5cab7f254690f329fac285128d8cd1c92

@leust leust marked this pull request as ready for review January 21, 2026 15:22
Copy link

@joker-at-work joker-at-work left a comment

Choose a reason for hiding this comment

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

Looks good, just 2 minor things.

Comment on lines +594 to +596
self.assertRaises(oslo_exceptions.MessagingTimeout,
self.compute_api.attach_volume,
self.context, instance, volume['id'])

Choose a reason for hiding this comment

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

Indentation is off by 2

objects.BlockDeviceMapping.get_by_volume_and_instance(
context, volume['id'], instance.uuid)
if bdm.attachment_id:
LOG.warning(

Choose a reason for hiding this comment

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

You sure this needs to be a warning? I think info would be enough - debug would be fine, too, imho.

Could we start the log-string on this same line like below for the LOG.debug after the bdm.destroy()?

When nova-api calls reserve_block_device_name RPC to nova-compute and
the call times out, we try to clean up by deleting the BDM entry. However,
during the timeout window a second attachment request for the same volume
can come in, create a valid BDM, and progress to talking to Cinder.
The original timed-out request then deletes this new valid BDM, leaving
the volume in an inconsistent state.

We fix this by checking if the BDM has attachment_id set before
deleting it. The attachment_id field is only populated in
_check_attach_and_reserve_volume(), which we only call after the
reserve_block_device_name RPC succeeds. If attachment_id is set,
we know the BDM belongs to a subsequent request that has already
progressed past the RPC phase, so we should not delete it.

Change-Id: I7ed649a5cab7f254690f329fac285128d8cd1c92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants