From ab785aa9920a88dd31b063c97f0676ae3d07ea82 Mon Sep 17 00:00:00 2001 From: sawka Date: Fri, 14 Jun 2024 10:09:28 -0700 Subject: [PATCH] move DeleteZone to its own go routine -- crazy bug where we used the wrong DB conn --- pkg/wstore/wstore_dbops.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/wstore/wstore_dbops.go b/pkg/wstore/wstore_dbops.go index 5ab036027..e2cc7a019 100644 --- a/pkg/wstore/wstore_dbops.go +++ b/pkg/wstore/wstore_dbops.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "log" + "time" "github.com/wavetermdev/thenextwave/pkg/filestore" "github.com/wavetermdev/thenextwave/pkg/waveobj" @@ -179,10 +180,16 @@ func DBDelete(ctx context.Context, otype string, id string) error { if err != nil { return err } - err = filestore.WFS.DeleteZone(ctx, id) - if err != nil { - log.Printf("error deleting filestore zone (after deleting block): %v", err) - } + go func() { + // we spawn a go routine here because we don't want to reuse the DB connection + // since DBDelete is called in a transaction from DeleteTab + deleteCtx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) + defer cancelFn() + err := filestore.WFS.DeleteZone(deleteCtx, id) + if err != nil { + log.Printf("error deleting filestore zone (after deleting block): %v", err) + } + }() return nil }