Skip to content

Commit

Permalink
Remove daemon InitDone guard in interrupt handler
Browse files Browse the repository at this point in the history
Instead of just terminating right there and then, we cancel the
context, and let the daemon exit cleanly. This make take a few
seconds, as the node builder and its child processes do not
care too much about the context state while building nodes,
but this can be improved by injecting checks for ctx.Done()
before time-consuming steps.
  • Loading branch information
torarnv committed Apr 17, 2015
1 parent 158adff commit ef409c0
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
3 changes: 0 additions & 3 deletions cmd/ipfs/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
corehttp.VersionOption(),
}

// our global interrupt handler can now try to stop the daemon
close(req.Context().InitDone)

if rootRedirect != nil {
opts = append(opts, rootRedirect)
}
Expand Down
17 changes: 0 additions & 17 deletions cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,6 @@ func main() {
os.Exit(1)
}

// our global interrupt handler may try to stop the daemon
// before the daemon is ready to be stopped; this dirty
// workaround is for the daemon only; other commands are always
// ready to be stopped
if invoc.cmd != daemonCmd {
close(invoc.req.Context().InitDone)
}

// ok, finally, run the command invocation.
intrh, ctx := invoc.SetupInterruptHandler(ctx)
defer intrh.Close()
Expand Down Expand Up @@ -518,15 +510,6 @@ func (i *cmdInvocation) SetupInterruptHandler(ctx context.Context) (io.Closer, c
case 1:
fmt.Println() // Prevent un-terminated ^C character in terminal

ctx := i.req.Context()

// if we're still initializing, cannot use `ctx.GetNode()`
select {
default: // initialization not done
os.Exit(-1)
case <-ctx.InitDone:
}

ih.wg.Add(1)
go func() {
defer ih.wg.Done()
Expand Down
3 changes: 1 addition & 2 deletions commands/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type Context struct {

node *core.IpfsNode
ConstructNode func() (*core.IpfsNode, error)
InitDone chan bool
}

// GetConfig returns the config of the current Command exection
Expand Down Expand Up @@ -288,7 +287,7 @@ func NewRequest(path []string, opts OptMap, args []string, file files.File, cmd
optDefs = make(map[string]Option)
}

ctx := Context{Context: context.TODO(), InitDone: make(chan bool)}
ctx := Context{Context: context.TODO()}
values := make(map[string]interface{})
req := &request{path, opts, args, file, cmd, ctx, optDefs, values, os.Stdin}
err := req.ConvertOptions()
Expand Down

0 comments on commit ef409c0

Please sign in to comment.