Skip to content

Commit

Permalink
core/godebuginstance: fix: properly wait for cmd to finish.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmigpin committed Feb 22, 2024
1 parent 642e813 commit 9f82696
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion core/godebuginstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
})

Expand All @@ -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()
}

Expand Down

0 comments on commit 9f82696

Please sign in to comment.