Skip to content

Commit

Permalink
fix(cmd): stop generators as last to avoid deadlock on exit
Browse files Browse the repository at this point in the history
As jobs unconditionally read from generator's channel there can be
a situation when generator is closed and will not produce
any new values while some jobs still wait on empty channel deadlocking
and preventing process exit.
  • Loading branch information
nuivall committed Jun 22, 2023
1 parent f802c33 commit 9b80747
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit 9b80747

Please sign in to comment.