Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: call app.Stop once #6380

Merged
merged 1 commit into from
May 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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