Skip to content

Commit fdecd41

Browse files
authored
Merge pull request #20 from travisperson/fix/error-if-node-goes-away
fix: error when nodes goes away
2 parents a4df063 + 0e90016 commit fdecd41

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

cmd/filsnap/cmds/create.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,9 @@ var cmdCreate = &cli.Command{
243243
r, w := io.Pipe()
244244

245245
e := export.NewExport(node, tsk, abi.ChainEpoch(flagStaterootCount), true, w)
246-
246+
errCh := make(chan error)
247247
go func() {
248-
if err := e.Export(ctx); err != nil {
249-
logger.Errorw("error", "err", err)
250-
}
248+
errCh <- e.Export(ctx)
251249
}()
252250

253251
go func() {
@@ -277,6 +275,10 @@ var cmdCreate = &cli.Command{
277275
select {
278276
case <-time.After(flagProgressUpdate):
279277
size, done := e.Progress()
278+
if size == 0 {
279+
continue
280+
}
281+
280282
if done {
281283
return
282284
}
@@ -313,6 +315,10 @@ var cmdCreate = &cli.Command{
313315
)
314316
}
315317

318+
if err := <-errCh; err != nil {
319+
return err
320+
}
321+
316322
logger.Infow("finished")
317323

318324
return nil

pkg/export/export.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package export
22

33
import (
44
"context"
5+
"fmt"
56
"io"
67
"sync"
78
"time"
@@ -47,6 +48,8 @@ func GetNextSnapshotHeight(current, interval, confidence abi.ChainEpoch, after b
4748
func waitAPIDown(ctx context.Context, node api.FullNode) error {
4849
ctx, cancel := context.WithTimeout(ctx, 300*time.Second)
4950
defer cancel()
51+
52+
logger.Infow("waiting for node to go offline")
5053
for {
5154
if ctx.Err() != nil {
5255
return ctx.Err()
@@ -66,6 +69,8 @@ func waitAPIDown(ctx context.Context, node api.FullNode) error {
6669
func waitAPI(ctx context.Context, node api.FullNode) error {
6770
ctx, cancel := context.WithTimeout(ctx, 300*time.Second)
6871
defer cancel()
72+
73+
logger.Infow("waiting for node to come online")
6974
for {
7075
if ctx.Err() != nil {
7176
return ctx.Err()
@@ -134,13 +139,14 @@ func (e *Export) Export(ctx context.Context) error {
134139
}
135140

136141
if err := waitAPIDown(ctx, e.node); err != nil {
137-
return err
142+
return fmt.Errorf("node failed to go offline: %w", err)
138143
}
139144

140145
if err := waitAPI(ctx, e.node); err != nil {
141-
return err
146+
return fmt.Errorf("node failed to come back online: %w", err)
142147
}
143148

149+
logger.Infow("starting export")
144150
stream, err := e.node.ChainExport(ctx, e.nroots, e.oldmsgskip, e.tsk)
145151
if err != nil {
146152
return err

0 commit comments

Comments
 (0)