aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--cmd/mbf/daemon.go3
-rw-r--r--internal/pkg/pkg.go9
-rw-r--r--internal/pkg/pkg_test.go21
3 files changed, 27 insertions, 6 deletions
diff --git a/cmd/mbf/daemon.go b/cmd/mbf/daemon.go
index a40eb27d..a32ccf59 100644
--- a/cmd/mbf/daemon.go
+++ b/cmd/mbf/daemon.go
@@ -194,6 +194,9 @@ func serve(
}
case specialAbort:
+ if _err := conn.Close(); _err != nil {
+ log.Println(_err)
+ }
log.Println("aborting all pending cures")
cm.c.Abort()
}
diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go
index 0ad39a4b..e94cf9c4 100644
--- a/internal/pkg/pkg.go
+++ b/internal/pkg/pkg.go
@@ -1120,7 +1120,7 @@ func (c *Cache) Done(id unique.Handle[ID]) <-chan struct{} {
// Cancel cancels the ongoing cure of an [Artifact] referred to by the specified
// identifier. Cancel returns whether the [context.CancelFunc] has been killed.
-// Cancel does not wait for the cure to complete.
+// Cancel returns after the cure is complete.
func (c *Cache) Cancel(id unique.Handle[ID]) bool {
c.identMu.RLock()
pending, ok := c.identPending[id]
@@ -1129,6 +1129,13 @@ func (c *Cache) Cancel(id unique.Handle[ID]) bool {
return false
}
pending.cancel()
+ <-pending.done
+
+ c.abortMu.Lock()
+ c.identMu.Lock()
+ delete(c.identErr, id)
+ c.identMu.Unlock()
+ c.abortMu.Unlock()
return true
}
diff --git a/internal/pkg/pkg_test.go b/internal/pkg/pkg_test.go
index 3110ed06..f3011902 100644
--- a/internal/pkg/pkg_test.go
+++ b/internal/pkg/pkg_test.go
@@ -911,7 +911,7 @@ func TestCache(t *testing.T) {
var started sync.WaitGroup
defer started.Wait()
- blockCures := func(d byte, n int) {
+ blockCures := func(d byte, e stub.UniqueError, n int) {
started.Add(n)
for i := range n {
wg.Go(func() {
@@ -920,9 +920,9 @@ func TestCache(t *testing.T) {
cure: func(t *pkg.TContext) error {
started.Done()
<-t.Unwrap().Done()
- return stub.UniqueError(0xbad0 + i)
+ return e + stub.UniqueError(i)
},
- }}); !reflect.DeepEqual(err, stub.UniqueError(0xbad0+i)) {
+ }}); !reflect.DeepEqual(err, e+stub.UniqueError(i)) {
panic(err)
}
})
@@ -930,15 +930,26 @@ func TestCache(t *testing.T) {
started.Wait()
}
- blockCures(0xfd, 16)
+ blockCures(0xfd, 0xbad, 16)
c.Abort()
wg.Wait()
- blockCures(0xff, 1)
+ blockCures(0xfd, 0xcafe, 16)
+ c.Abort()
+ wg.Wait()
+
+ blockCures(0xff, 0xbad, 1)
if !c.Cancel(unique.Make(pkg.ID{0xff})) {
t.Fatal("missed cancellation")
}
wg.Wait()
+
+ blockCures(0xff, 0xcafe, 1)
+ if !c.Cancel(unique.Make(pkg.ID{0xff})) {
+ t.Fatal("missed cancellation")
+ }
+ wg.Wait()
+
for c.Cancel(unique.Make(pkg.ID{0xff})) {
}