nixstore/remotestore: add a mutex around the connection

This commit is contained in:
Luke Granger-Brown 2022-10-10 01:28:26 +01:00
parent 730f157cb1
commit 20617e22f1

View file

@ -7,6 +7,7 @@ import (
"net" "net"
"path" "path"
"strings" "strings"
"sync"
"hg.lukegb.com/lukegb/depot/go/nix/nar/narinfo" "hg.lukegb.com/lukegb/depot/go/nix/nar/narinfo"
"hg.lukegb.com/lukegb/depot/go/nix/nixwire" "hg.lukegb.com/lukegb/depot/go/nix/nixwire"
@ -26,9 +27,14 @@ type Daemon struct {
conn net.Conn conn net.Conn
w *nixwire.Serializer w *nixwire.Serializer
r *nixwire.Deserializer r *nixwire.Deserializer
mu sync.Mutex
err error
} }
func (d *Daemon) NARInfo(storePath string) (*narinfo.NarInfo, 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 { if _, err := d.w.WriteUint64(WopQueryPathInfo); err != nil {
return nil, fmt.Errorf("writing worker op WopQueryPathInfo: %w", err) 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 { func (d *Daemon) Close() error {
d.mu.Lock()
defer d.mu.Unlock()
return d.conn.Close() return d.conn.Close()
} }