diff --git a/cmd/zb/config.go b/cmd/zb/config.go index 73301a6..6e1f85e 100644 --- a/cmd/zb/config.go +++ b/cmd/zb/config.go @@ -11,7 +11,6 @@ import ( "net" "os" "path/filepath" - "sync" jsonv2 "github.com/go-json-experiment/json" "github.com/go-json-experiment/json/jsontext" @@ -173,16 +172,14 @@ func (g *globalConfig) reusePolicy() *zbstorerpc.ReusePolicy { return &zbstorerpc.ReusePolicy{PublicKeys: g.TrustedPublicKeys} } -func (g *globalConfig) storeClient(opts *zbstorerpc.CodecOptions) (_ *jsonrpc.Client, wait func()) { - var wg sync.WaitGroup - c := jsonrpc.NewClient(func(ctx context.Context) (jsonrpc.ClientCodec, error) { +func (g *globalConfig) storeClient(opts *zbstorerpc.CodecOptions) *jsonrpc.Client { + return jsonrpc.NewClient(func(ctx context.Context) (jsonrpc.ClientCodec, error) { conn, err := (&net.Dialer{}).DialContext(ctx, "unix", g.StoreSocket) if err != nil { return nil, err } return zbstorerpc.NewCodec(conn, opts), nil }) - return c, wg.Wait } // defaultVarDir returns "/opt/zb/var/zb" on Unix-like systems or `C:\zb\var\zb` on Windows systems. diff --git a/cmd/zb/derivation.go b/cmd/zb/derivation.go index c9f607b..6d10530 100644 --- a/cmd/zb/derivation.go +++ b/cmd/zb/derivation.go @@ -110,13 +110,10 @@ func runDerivationShow(ctx context.Context, g *globalConfig, opts *derivationSho } di := new(zbstorerpc.DeferredImporter) - storeClient, waitStoreClient := g.storeClient(&zbstorerpc.CodecOptions{ + storeClient := g.storeClient(&zbstorerpc.CodecOptions{ Importer: di, }) - defer func() { - storeClient.Close() - waitStoreClient() - }() + defer storeClient.Close() eval, err := opts.newEval(g, storeClient, di) if err != nil { return err @@ -358,13 +355,10 @@ func newDerivationEnvCommand(g *globalConfig) *cobra.Command { func runDerivationEnv(ctx context.Context, g *globalConfig, opts *derivationEnvOptions) error { di := new(zbstorerpc.DeferredImporter) - storeClient, waitStoreClient := g.storeClient(&zbstorerpc.CodecOptions{ + storeClient := g.storeClient(&zbstorerpc.CodecOptions{ Importer: di, }) - defer func() { - storeClient.Close() - waitStoreClient() - }() + defer storeClient.Close() eval, err := opts.newEval(g, storeClient, di) if err != nil { return err diff --git a/cmd/zb/main.go b/cmd/zb/main.go index f425a81..abbadc1 100644 --- a/cmd/zb/main.go +++ b/cmd/zb/main.go @@ -181,13 +181,10 @@ func newEvalCommand(g *globalConfig) *cobra.Command { func runEval(ctx context.Context, g *globalConfig, opts *evalOptions) error { di := new(zbstorerpc.DeferredImporter) - storeClient, waitStoreClient := g.storeClient(&zbstorerpc.CodecOptions{ + storeClient := g.storeClient(&zbstorerpc.CodecOptions{ Importer: di, }) - defer func() { - storeClient.Close() - waitStoreClient() - }() + defer storeClient.Close() eval, err := opts.newEval(g, storeClient, di) if err != nil { return err @@ -250,13 +247,10 @@ func newBuildCommand(g *globalConfig) *cobra.Command { func runBuild(ctx context.Context, g *globalConfig, opts *buildOptions) error { di := new(zbstorerpc.DeferredImporter) - storeClient, waitStoreClient := g.storeClient(&zbstorerpc.CodecOptions{ + storeClient := g.storeClient(&zbstorerpc.CodecOptions{ Importer: di, }) - defer func() { - storeClient.Close() - waitStoreClient() - }() + defer storeClient.Close() eval, err := opts.newEval(g, storeClient, di) if err != nil { return err diff --git a/cmd/zb/store.go b/cmd/zb/store.go index 146bc2f..08fbe85 100644 --- a/cmd/zb/store.go +++ b/cmd/zb/store.go @@ -85,11 +85,8 @@ func newStoreObjectInfoCommand(g *globalConfig) *cobra.Command { } func runStoreObjectInfo(ctx context.Context, g *globalConfig, opts *storeObjectInfoOptions) error { - storeClient, waitStoreClient := g.storeClient(nil) - defer func() { - storeClient.Close() - waitStoreClient() - }() + storeClient := g.storeClient(nil) + defer storeClient.Close() const errNotExist = "does not exist" @@ -196,13 +193,10 @@ func runStoreObjectExport(ctx context.Context, g *globalConfig, opts *storeObjec toOutput := zbstorerpc.ImportFunc(func(header jsonrpc.Header, body io.Reader) error { return zbstore.ReceiveExport(nopReceiver{}, io.TeeReader(body, opts.output)) }) - storeClient, waitStoreClient := g.storeClient(&zbstorerpc.CodecOptions{ + storeClient := g.storeClient(&zbstorerpc.CodecOptions{ Importer: toOutput, }) - defer func() { - storeClient.Close() - waitStoreClient() - }() + defer storeClient.Close() req := &zbstorerpc.ExportRequest{ Paths: make([]zbstore.Path, len(opts.paths)), @@ -254,11 +248,8 @@ func newStoreObjectImportCommand(g *globalConfig) *cobra.Command { } func runStoreObjectImport(ctx context.Context, g *globalConfig, opts *storeObjectImportOptions) error { - storeClient, waitStoreClient := g.storeClient(nil) - defer func() { - storeClient.Close() - waitStoreClient() - }() + storeClient := g.storeClient(nil) + defer storeClient.Close() inputPaths := opts.paths if len(inputPaths) == 0 {