From 9f8269658351014b4a10d417360d1a5292fe06c5 Mon Sep 17 00:00:00 2001 From: Jorge Miguel Pinto Date: Thu, 22 Feb 2024 12:37:47 +0000 Subject: [PATCH] core/godebuginstance: fix: properly wait for cmd to finish. --- core/godebuginstance.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/godebuginstance.go b/core/godebuginstance.go index 976554ac..93a8010f 100644 --- a/core/godebuginstance.go +++ b/core/godebuginstance.go @@ -142,6 +142,8 @@ type GoDebugInstance struct { cancel context.CancelFunc gdm *GoDebugManager di *GDDataIndex + + cmdWait sync.WaitGroup } func newGoDebugInstance(ctx context.Context, gdm *GoDebugManager, erow *ERow, args []string) (*GoDebugInstance, error) { @@ -163,7 +165,9 @@ func newGoDebugInstance(ctx context.Context, gdm *GoDebugManager, erow *ERow, ar return nil, fmt.Errorf("can't run on this erow type") } + gdi.cmdWait.Add(1) _, cancel := erow.Exec.RunAsyncWithCancel(func(erowCtx context.Context, rw io.ReadWriter) error { + defer gdi.cmdWait.Done() return gdi.runCmd(erowCtx, erow, args, rw) }) @@ -179,7 +183,7 @@ func newGoDebugInstance(ctx context.Context, gdm *GoDebugManager, erow *ERow, ar } func (gdi *GoDebugInstance) cancelAndWaitAndClear() { gdi.cancel() - <-gdi.ctx.Done() + gdi.cmdWait.Wait() gdi.clearAnnotations() }