diff --git a/bundle/deploy/files/upload.go b/bundle/deploy/files/upload.go index 9c9cf778f..77b83611b 100644 --- a/bundle/deploy/files/upload.go +++ b/bundle/deploy/files/upload.go @@ -12,7 +12,7 @@ import ( ) type upload struct { - outpuHandler sync.OutputHandler + outputHandler sync.OutputHandler } func (m *upload) Name() string { @@ -26,19 +26,18 @@ func (m *upload) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { return diag.FromErr(err) } - opts.OutputHandler = m.outpuHandler + opts.OutputHandler = m.outputHandler sync, err := sync.New(ctx, *opts) if err != nil { return diag.FromErr(err) } + defer sync.Close() b.Files, err = sync.RunOnce(ctx) if err != nil { return diag.FromErr(err) } - sync.Close() - log.Infof(ctx, "Uploaded bundle files") return nil } diff --git a/cmd/sync/sync.go b/cmd/sync/sync.go index d16b2b83b..2092d9e33 100644 --- a/cmd/sync/sync.go +++ b/cmd/sync/sync.go @@ -134,6 +134,7 @@ func New() *cobra.Command { if err != nil { return err } + defer s.Close() if f.watch { err = s.RunContinuous(ctx) @@ -141,7 +142,6 @@ func New() *cobra.Command { _, err = s.RunOnce(ctx) } - s.Close() return err } diff --git a/libs/sync/sync.go b/libs/sync/sync.go index b61af44a2..cc9c73944 100644 --- a/libs/sync/sync.go +++ b/libs/sync/sync.go @@ -52,9 +52,12 @@ type Sync struct { filer filer.Filer // Synchronization progress events are sent to this event notifier. - notifier EventNotifier + notifier EventNotifier + seq int + + // WaitGroup is automatically created when an output handler is provided in the SyncOptions. + // Close call is required to ensure the output handler goroutine handles all events in time. outputWaitGroup *stdsync.WaitGroup - seq int } // New initializes and returns a new [Sync] instance. @@ -140,12 +143,6 @@ func New(ctx context.Context, opts SyncOptions) (*Sync, error) { }, nil } -func (s *Sync) Events() <-chan Event { - ch := make(chan Event, MaxRequestsInFlight) - s.notifier = &ChannelNotifier{ch} - return ch -} - func (s *Sync) Close() { if s.notifier == nil { return