diff --git a/nip13/nip13.go b/nip13/nip13.go index 642ca28..6cd68b3 100644 --- a/nip13/nip13.go +++ b/nip13/nip13.go @@ -87,6 +87,7 @@ func DoWork(ctx context.Context, event nostr.Event, targetDifficulty int) (nostr } ctx, cancel := context.WithCancel(ctx) + defer cancel() nthreads := runtime.NumCPU() tagCh := make(chan nostr.Tag) diff --git a/nip13/nip13_test.go b/nip13/nip13_test.go index 323bfd8..9dedb2a 100644 --- a/nip13/nip13_test.go +++ b/nip13/nip13_test.go @@ -79,7 +79,8 @@ func TestDoWorkLong(t *testing.T) { Content: "It's just me mining my own business", PubKey: "a48380f4cfcc1ad5378294fcac36439770f9c878dd880ffa94bb74ea54a6f243", } - ctx, _ := context.WithTimeout(context.Background(), time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() pow, err := DoWork(ctx, event, difficulty) if err != nil { t.Fatal(err) @@ -114,7 +115,8 @@ func TestDoWorkTimeout(t *testing.T) { } done := make(chan error) go func() { - ctx, _ := context.WithTimeout(context.Background(), time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond) + defer cancel() _, err := DoWork(ctx, event, 256) done <- err }()