Skip to content

Commit

Permalink
exit status check and make sure loops return
Browse files Browse the repository at this point in the history
the create command doesn't exit properly after a snapshot completes
  • Loading branch information
ognots committed Apr 24, 2023
1 parent 55bb87d commit 88dcb4c
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions cmd/filecoin-chain-archiver/cmds/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ var cmdCreate = &cli.Command{

logger.Debugw("lock aquired", "expiry", lock.Expiry())
}
break
}
}()

Expand Down Expand Up @@ -400,6 +401,9 @@ var cmdCreate = &cli.Command{
if size == 0 {
continue
}
if size == lastSize {
break
}
logger.Infow("update", "total", size, "speed", (size-lastSize)/int64(flagProgressUpdate/time.Second))
lastSize = size
case err := <-errCh:
Expand All @@ -408,21 +412,12 @@ var cmdCreate = &cli.Command{
}
}
}
return
}()

if flagDiscard {
logger.Infow("discarding output")
g, ctxGroup := errgroup.WithContext(ctx)
g.Go(func() error {
return runWriteCompressed(ctxGroup, rrPath+".zstd", rr)
})
if err := g.Wait(); err != nil {
return err
}

if err := <-errCh; err != nil {
return err
}
return runWriteCompressed(rrPath+".zstd", rr)
} else {
host := u.Hostname()
port := u.Port()
Expand Down Expand Up @@ -514,7 +509,7 @@ func compress(source io.Reader) io.Reader {
return r
}

func runWriteCompressed(ctx context.Context, path string, source io.Reader) error {
func runWriteCompressed(path string, source io.Reader) error {
file, err := os.Create(path)
if err != nil {
return err
Expand Down

0 comments on commit 88dcb4c

Please sign in to comment.