From 4fb5034f8199611ae221e36bda0db0efa5df940a Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 13 Dec 2017 09:38:29 -0800 Subject: [PATCH] Destroy event history collectors The EventHistoryCollector objects are tied to a session and there is a max per-session. Without destroying the collectors, we could max out the collectors causing 'govc events' to return empty. Fixes #948 Fixes #961 --- event/manager.go | 2 ++ event/processor.go | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) 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..da78188e3 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,12 +68,18 @@ 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 @@ -81,7 +87,7 @@ func (p *eventProcessor) run(ctx context.Context, tail bool) error { var collectors []types.ManagedObjectReference for _, t := range p.tailers { - collectors = append(collectors, t.collector) + collectors = append(collectors, t.collector.Reference()) } c := property.DefaultCollector(p.mgr.Client())