fix: data race in configureDevices with PropertyCollector in vcsim#3947
Open
Joshzxj wants to merge 1 commit intovmware:mainfrom
Open
fix: data race in configureDevices with PropertyCollector in vcsim#3947Joshzxj wants to merge 1 commit intovmware:mainfrom
Joshzxj wants to merge 1 commit intovmware:mainfrom
Conversation
578b5fb to
80de3b0
Compare
Author
|
Unit test failed might unrelated to this change, I see same sympton on https://github.com/vmware/govmomi/actions/runs/20923278206 |
Use cloneDevice() to create a deep copy of the device list before modification, preventing race between AssignController writes and PropertyCollector's deepCopy reads.. Signed-off-by: Zexing Jiang <zexing.jiang@broadcom.com>
80de3b0 to
24c2602
Compare
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.
Description
Use cloneDevice() to create a deep copy of the device list before modification, preventing race between AssignController writes and PropertyCollector's deepCopy reads.
I was hitting a race between
A data race occurs between two concurrent operations:
AssignController()inobject/virtual_device_list.go:547appends tocontroller.Deviceslice duringReconfigVMTaskhas been called.deepCopy()insimulator/object.go:51marshals VM properties (including the same controller) duringPropertyCollector.RetrievePropertiesEx()The fix is to use deep copy of devicelist to do config device.
With shared slice (without fix):
configureDevices() starts
├─> devices points to SAME array as vm.Config.Hardware.Device
├─> AssignController modifies controller.Device
│ └─> VM sees PARTIAL changes immediately (inconsistent state)
└─> ctx.Update() - already partially modified
With deep copy (with fix):
configureDevices() starts
├─> devices is a SEPARATE copy
├─> AssignController modifies the COPY
│ └─> VM still has OLD state (consistent)
└─> ctx.Update() replaces VM's devices with modified copy
└─> VM now has NEW state (consistent)
How Has This Been Tested?
It is hard to repo inside vcsim package with the whole
AssignControllercall .I wrote similiar code to mimic what AssignController did(Especially focus on directly inplace replacement device slice by append) , it 100% reproduce the same backtrace.
Guidelines
Please read and follow the
CONTRIBUTIONguidelines of this project.