Skip to content

Commit

Permalink
fix(fsrepo): close fsrepo on context cancellation
Browse files Browse the repository at this point in the history
not properly closing the opened fsrepo instance on context completion was causing the ipfs cafs to retain the repo lock past the context deadline
  • Loading branch information
b5 committed May 1, 2019
1 parent 43a6e0f commit ff18631
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 6 additions & 2 deletions cafs/ipfs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func OptsFromMap(opts map[string]interface{}) Option {
}
}

func (cfg *StoreCfg) InitRepo() error {
func (cfg *StoreCfg) InitRepo(ctx context.Context) error {
if cfg.NilRepo {
return nil
}
Expand All @@ -88,8 +88,12 @@ func (cfg *StoreCfg) InitRepo() error {
if err == fsrepo.ErrNeedMigration {
return ErrIPFSRepoNeedsMigration
}
return fmt.Errorf("error opening local filestore ipfs repository: %s\n", err.Error())
return fmt.Errorf("error opening local filestore ipfs repository: %s", err.Error())
}
go func() {
<-ctx.Done()
localRepo.Close()
}()
cfg.Repo = localRepo
}
return nil
Expand Down
9 changes: 5 additions & 4 deletions cafs/ipfs/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"io"

logging "github.com/ipfs/go-log"
cafs "github.com/qri-io/qfs/cafs"
"github.com/qri-io/qfs"
cafs "github.com/qri-io/qfs/cafs"

// Note coreunix is forked form github.com/ipfs/go-ipfs/core/coreunix
// we need coreunix.Adder.addFile to be exported to get access to dags while
Expand Down Expand Up @@ -54,7 +54,7 @@ func NewFilestore(config ...Option) (*Filestore, error) {
}, nil
}

if err := cfg.InitRepo(); err != nil {
if err := cfg.InitRepo(cfg.Ctx); err != nil {
return nil, err
}

Expand All @@ -78,10 +78,11 @@ func (fst *Filestore) Online() bool {
return fst.node.OnlineMode()
}

func (fst *Filestore) GoOnline() error {
func (fst *Filestore) GoOnline(ctx context.Context) error {
log.Debug("going online")
cfg := fst.cfg
cfg.BuildCfg.Online = true
node, err := core.NewNode(cfg.Ctx, &cfg.BuildCfg)
node, err := core.NewNode(ctx, &cfg.BuildCfg)
if err != nil {
return fmt.Errorf("error creating ipfs node: %s\n", err.Error())
}
Expand Down

0 comments on commit ff18631

Please sign in to comment.