Skip to content

Commit f13754e

Browse files
committed
fix: vcsim: extend PropertyCollector lock to avoid potential races
The collect() method needs to continue holding the object lock while processing selectSet. Fixes #3697 Signed-off-by: Doug MacEachern <[email protected]>
1 parent 1d5b2cc commit f13754e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

simulator/property_collector.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -531,21 +531,23 @@ func collect(ctx *Context, r *types.RetrievePropertiesEx) (*types.RetrieveResult
531531
// Select object references
532532
for _, spec := range r.SpecSet {
533533
for _, o := range spec.ObjectSet {
534-
var rval reflect.Value
535-
ok := false
536-
ctx.WithLock(o.Obj, func() { rval, ok = getObject(ctx, o.Obj) })
534+
unlock := ctx.Map.AcquireLock(ctx, o.Obj)
535+
rval, ok := getObject(ctx, o.Obj)
537536
if !ok {
537+
unlock()
538538
if isFalse(spec.ReportMissingObjectsInResults) {
539539
return nil, &types.ManagedObjectNotFound{Obj: o.Obj}
540540
}
541541
continue
542542
}
543543

544544
if o.SelectSet == nil || isFalse(o.Skip) {
545-
refs = append(refs, o.Obj)
545+
rr.collect(ctx, o.Obj)
546546
}
547547

548-
if err := rr.selectSet(ctx, rval, o.SelectSet, &refs); err != nil {
548+
err := rr.selectSet(ctx, rval, o.SelectSet, &refs)
549+
unlock()
550+
if err != nil {
549551
return nil, err
550552
}
551553
}

0 commit comments

Comments
 (0)