diff --git a/event/manager.go b/event/manager.go index 3feede10e..d3f2da9a7 100644 --- a/event/manager.go +++ b/event/manager.go @@ -180,5 +180,7 @@ func (m Manager) Events(ctx context.Context, objects []types.ManagedObjectRefere proc.addObject(ctx, o) } + defer proc.destroy() + return proc.run(ctx, tail) } diff --git a/event/processor.go b/event/processor.go index 18084d489..cc19b7009 100644 --- a/event/processor.go +++ b/event/processor.go @@ -28,7 +28,7 @@ import ( type tailInfo struct { t *eventTailer obj types.ManagedObjectReference - collector types.ManagedObjectReference + collector *HistoryCollector } type eventProcessor struct { @@ -68,20 +68,26 @@ func (p *eventProcessor) addObject(ctx context.Context, obj types.ManagedObjectR p.tailers[collector.Reference()] = &tailInfo{ t: newEventTailer(), obj: obj, - collector: collector.Reference(), + collector: collector, } return nil } +func (p *eventProcessor) destroy() { + for _, info := range p.tailers { + _ = info.collector.Destroy(context.Background()) + } +} + func (p *eventProcessor) run(ctx context.Context, tail bool) error { if len(p.tailers) == 0 { return nil } var collectors []types.ManagedObjectReference - for _, t := range p.tailers { - collectors = append(collectors, t.collector) + for ref := range p.tailers { + collectors = append(collectors, ref) } c := property.DefaultCollector(p.mgr.Client())