diff --git a/cmd/block-generator/runner/run.go b/cmd/block-generator/runner/run.go index 561aac03a..8c1141e6e 100644 --- a/cmd/block-generator/runner/run.go +++ b/cmd/block-generator/runner/run.go @@ -87,11 +87,23 @@ func (r *Args) run() error { algodNet := fmt.Sprintf("localhost:%d", 11112) indexerNet := fmt.Sprintf("localhost:%d", r.IndexerPort) generatorShutdownFunc, generator := startGenerator(r.Path, algodNet, blockMiddleware) + defer func() { + // Shutdown generator. + if err := generatorShutdownFunc(); err != nil { + fmt.Printf("Failed to shutdown generator: %s\n", err) + } + }() indexerShutdownFunc, err := startIndexer(logfile, r.LogLevel, r.IndexerBinary, algodNet, indexerNet, r.PostgresConnectionString, r.CPUProfilePath) if err != nil { return fmt.Errorf("failed to start indexer: %w", err) } + defer func() { + // Shutdown indexer + if err := indexerShutdownFunc(); err != nil { + fmt.Printf("Failed to shutdown indexer: %s\n", err) + } + }() // Create the report file report, err := os.Create(reportfile) @@ -118,16 +130,6 @@ func (r *Args) run() error { } } - // Shutdown generator. - if err := generatorShutdownFunc(); err != nil { - return err - } - - // Shutdown indexer - if err := indexerShutdownFunc(); err != nil { - return err - } - return nil }