From 20617e22f11865c7f608dae19b85f3f393c0299b Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Mon, 10 Oct 2022 01:28:26 +0100 Subject: [PATCH] nixstore/remotestore: add a mutex around the connection --- go/nix/nixstore/remotestore.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/go/nix/nixstore/remotestore.go b/go/nix/nixstore/remotestore.go index 85bed91f86..c5a69b0eb2 100644 --- a/go/nix/nixstore/remotestore.go +++ b/go/nix/nixstore/remotestore.go @@ -7,6 +7,7 @@ import ( "net" "path" "strings" + "sync" "hg.lukegb.com/lukegb/depot/go/nix/nar/narinfo" "hg.lukegb.com/lukegb/depot/go/nix/nixwire" @@ -26,9 +27,14 @@ type Daemon struct { conn net.Conn w *nixwire.Serializer r *nixwire.Deserializer + mu sync.Mutex + err error } func (d *Daemon) NARInfo(storePath string) (*narinfo.NarInfo, error) { + d.mu.Lock() + defer d.mu.Unlock() + if _, err := d.w.WriteUint64(WopQueryPathInfo); err != nil { return nil, fmt.Errorf("writing worker op WopQueryPathInfo: %w", err) } @@ -104,6 +110,9 @@ func (d *Daemon) NARInfo(storePath string) (*narinfo.NarInfo, error) { } func (d *Daemon) Close() error { + d.mu.Lock() + defer d.mu.Unlock() + return d.conn.Close() }