Skip to content

Commit e2c91b7

Browse files
committed
Fix error handling in tests file
If the errgroup fail (e.g. the writer crash), also stop the deadlineCtx which will cause program to stop. Without this, writers will stop and the program will hang.
1 parent 7ba4d84 commit e2c91b7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tests/remote-storage-bench/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,24 @@ func run(deadlineCtx context.Context) error {
9191
})
9292
}
9393

94-
ctx := context.Background()
94+
group, ctx := errgroup.WithContext(context.Background())
9595

9696
if *runDuration > 0 {
9797
var cancel context.CancelFunc
9898

9999
deadlineCtx, cancel = context.WithTimeout(deadlineCtx, *runDuration)
100100
defer cancel()
101+
102+
go func() {
103+
// If the errgroup context is stopped, stop the deadlineCtx.
104+
// deadlineCtx is used for work generation.
105+
// ctx (errgroup context) is used for writers.
106+
// We use two context, because work generation need to be stopped before writers
107+
<-ctx.Done()
108+
cancel()
109+
}()
101110
}
102111

103-
group, ctx := errgroup.WithContext(ctx)
104112
workChannel := make(chan prompb.WriteRequest, 10)
105113

106114
for _, writer := range writers {

0 commit comments

Comments
 (0)