Skip to content

Commit

Permalink
Merge pull request #6380 from ipfs/fix/app-stop-once
Browse files Browse the repository at this point in the history
core: call app.Stop once
  • Loading branch information
Stebalien authored May 25, 2019
2 parents 2192ed7 + 7cfb4aa commit 9847416
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 12 additions & 4 deletions core/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package core

import (
"context"
"sync"

"github.com/ipfs/go-metrics-interface"
"go.uber.org/fx"
Expand All @@ -27,19 +28,26 @@ func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) {
fx.Extract(n),
)

var once sync.Once
var stopErr error
n.stop = func() error {
once.Do(func() {
stopErr = app.Stop(context.Background())
})
return stopErr
}
n.IsOnline = cfg.Online

go func() {
// Note that some services use contexts to signal shutting down, which is
// very suboptimal. This needs to be here until that's addressed somehow
<-ctx.Done()
err := app.Stop(context.Background())
err := n.stop()
if err != nil {
log.Error("failure on stop: ", err)
}
}()

n.IsOnline = cfg.Online
n.app = app

if app.Err() != nil {
return nil, app.Err()
}
Expand Down
6 changes: 2 additions & 4 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"context"
"io"

"go.uber.org/fx"

version "github.com/ipfs/go-ipfs"
"github.com/ipfs/go-ipfs/core/bootstrap"
"github.com/ipfs/go-ipfs/core/node"
Expand Down Expand Up @@ -107,7 +105,7 @@ type IpfsNode struct {
Process goprocess.Process
ctx context.Context

app *fx.App
stop func() error

// Flags
IsOnline bool `optional:"true"` // Online is set when networking is enabled.
Expand All @@ -124,7 +122,7 @@ type Mounts struct {

// Close calls Close() on the App object
func (n *IpfsNode) Close() error {
return n.app.Stop(n.ctx)
return n.stop()
}

// Context returns the IpfsNode context
Expand Down

0 comments on commit 9847416

Please sign in to comment.