From 4e3399fc2a77d884528652066600c7a10786b8a8 Mon Sep 17 00:00:00 2001 From: erezrokah Date: Thu, 26 Jan 2023 15:13:36 +0200 Subject: [PATCH] fix: Only call `newExecutionClient` if needed --- plugins/source/plugin.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/source/plugin.go b/plugins/source/plugin.go index 57b7b3e56d..65db79d49b 100644 --- a/plugins/source/plugin.go +++ b/plugins/source/plugin.go @@ -221,12 +221,12 @@ func (p *Plugin) Init(ctx context.Context, spec specs.Source) error { return fmt.Errorf("unknown backend: %s", spec.Backend) } - p.client, err = p.newExecutionClient(ctx, p.logger, spec, Options{Backend: p.backend}) - if err != nil { - return fmt.Errorf("failed to create execution client for source plugin %s: %w", p.name, err) - } tables := p.tables if p.getDynamicTables != nil { + p.client, err = p.newExecutionClient(ctx, p.logger, spec, Options{Backend: p.backend}) + if err != nil { + return fmt.Errorf("failed to create execution client for source plugin %s: %w", p.name, err) + } tables, err = p.getDynamicTables(ctx, p.client) if err != nil { return fmt.Errorf("failed to get dynamic tables: %w", err) @@ -272,6 +272,14 @@ func (p *Plugin) Sync(ctx context.Context, res chan<- *schema.Resource) error { } defer p.mu.Unlock() + if p.client == nil { + var err error + p.client, err = p.newExecutionClient(ctx, p.logger, p.spec, Options{Backend: p.backend}) + if err != nil { + return fmt.Errorf("failed to create execution client for source plugin %s: %w", p.name, err) + } + } + startTime := time.Now() switch p.spec.Scheduler { case specs.SchedulerDFS: