Skip to content

Commit

Permalink
back to wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jrick committed Jan 24, 2025
1 parent 27a89a9 commit 498b9b3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions spv/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,18 +426,29 @@ func (s *Syncer) Run(ctx context.Context) (err error) {
})

// Ensure wallet.Run cleanly finishes/is canceled first when outer
// context is canceled by passing in the outer context, not the
// errgroup's gctx.
// context is canceled.
walletCtx, walletCtxCancel := context.WithCancel(context.Background())
g.Go(func() error {
select {
case <-ctx.Done():
case <-gctx.Done():
}
walletCtxCancel()
// Do not cancel gctx yet; wait for wallet.Run to return.
return nil
})
g.Go(func() error {
// Run wallet background goroutines (currently, this just runs
// mixclient).
err := s.wallet.Run(ctx)
err := s.wallet.Run(walletCtx)
if err != nil {
return err
}
// Cancel gctx when outer ctx has errored/canceled.
<-ctx.Done()
return ctx.Err()

// If gctx has not yet been canceled, do so here now.
// walletCtx is canceled after either ctx or gctx is canceled.
<-walletCtx.Done()
return walletCtx.Err()
})

// Wait until cancellation or a handler errors.
Expand Down

0 comments on commit 498b9b3

Please sign in to comment.