Commit bfd12114 authored by Tor Arne Vestbø's avatar Tor Arne Vestbø Committed by Tor Arne Vestbø

Remove daemon InitDone guard in interrupt handler

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.
parent cf6a268c
......@@ -282,9 +282,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)
}
......
......@@ -132,14 +132,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()
......@@ -525,15 +517,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()
......
......@@ -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
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment