Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cmd): stop generators as last to avoid deadlock on exit #368

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmd/gemini/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ func run(_ *cobra.Command, _ []string) error {
stop.StartOsSignalsTransmitter(logger, &warmupStopFlag, &workStopFlag)
pump := jobs.NewPump(ctx, logger)

generators := createGenerators(ctx, schema, schemaConfig, distFunc, concurrency, partitionCount, logger)
genCtx, genCancel := context.WithCancel(context.Background())
generators := createGenerators(genCtx, schema, schemaConfig, distFunc, concurrency, partitionCount, logger)

if !nonInteractive {
sp := createSpinner(interactive())
Expand Down Expand Up @@ -294,8 +295,13 @@ func run(_ *cobra.Command, _ []string) error {
if err = jobsList.Run(ctx, schema, schemaConfig, st, pump, generators, globalStatus, logger, seed, &workStopFlag, failFast, verbose); err != nil {
logger.Debug("error detected", zap.Error(err))
}

}

// stop generators, this needs to be done after jobs finish
// because otherwise they can deadlock in pick() func waiting
// for more values to be generated
genCancel()

logger.Info("test finished")
globalStatus.PrintResult(outFile, schema, version)
if globalStatus.HasErrors() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/generators/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (g *Generator) start() {
g.fillAllPartitions()
select {
case <-gCtx.Done():
g.logger.Debug("stopping partition key generation loop",
g.logger.Info("stopping partition key generation loop",
zap.Uint64("keys_created", g.cntCreated),
zap.Uint64("keys_emitted", g.cntEmitted))
return gCtx.Err()
Expand Down
4 changes: 2 additions & 2 deletions pkg/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func mutationJob(
}
select {
case <-ctx.Done():
logger.Debug("mutation job terminated")
logger.Info("mutation job terminated")
return nil
case hb := <-pump:
time.Sleep(hb)
Expand Down Expand Up @@ -286,7 +286,7 @@ func warmupJob(
}
select {
case <-ctx.Done():
logger.Debug("warmup job terminated")
logger.Info("warmup job terminated")
return nil
default:
}
Expand Down