diff --git a/internal/client/basis.go b/internal/client/basis.go index de08c1e0e..6f03e8947 100644 --- a/internal/client/basis.go +++ b/internal/client/basis.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/vagrant-plugin-sdk/proto/vagrant_plugin_sdk" "github.com/hashicorp/vagrant-plugin-sdk/terminal" configpkg "github.com/hashicorp/vagrant/internal/config" + "github.com/hashicorp/vagrant/internal/runner" "github.com/hashicorp/vagrant/internal/server/proto/vagrant_server" "github.com/hashicorp/vagrant/internal/serverclient" ) @@ -36,6 +37,7 @@ type Basis struct { local bool localServer bool // True when a local server is created + localRunner *runner.Runner } func New(ctx context.Context, opts ...Option) (basis *Basis, err error) { diff --git a/internal/client/job.go b/internal/client/job.go index a864270c0..1f32c7157 100644 --- a/internal/client/job.go +++ b/internal/client/job.go @@ -59,18 +59,27 @@ func (b *Basis) doJob(ctx context.Context, job *vagrant_server.Job, ui terminal. // In local mode we have to start a runner. if b.local { - log.Info("local mode, starting local runner") - r, err := b.startRunner() - if err != nil { - return nil, err + + if b.localRunner == nil { + log.Info("local mode, starting local runner") + r, err := b.startRunner() + if err != nil { + return nil, err + } + + b.localRunner = r + b.cleanup(func() { r.Close() }) } - log.Info("runner started", "runner_id", r.Id()) + r := b.localRunner + + log.Info("using local runner", "runner_id", r.Id()) // We defer the close so that we clean up resources. Local mode // always blocks and streams the full output so when doJob exits // the job is complete. - defer r.Close() + + // defer r.Close() var jobCh chan struct{}