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.
Tor Arne Vestbø committed
Apr 17, 2015 at 18:31 UTC
bfd12114e7e915f5b5fca972d06ddb09953f4658
3 files changed
+1
-22
cmd/ipfs/daemon.go
-3
@@ -282,9 +282,6 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
282
corehttp.VersionOption(),
283
}
284
285
- // our global interrupt handler can now try to stop the daemon
286
- close(req.Context().InitDone)
287
-
285
if rootRedirect != nil {
286
opts = append(opts, rootRedirect)
287
}
cmd/ipfs/main.go
-17
@@ -132,14 +132,6 @@ func main() {
132
os.Exit(1)
133
}
134
135
- // our global interrupt handler may try to stop the daemon
136
- // before the daemon is ready to be stopped; this dirty
137
- // workaround is for the daemon only; other commands are always
138
- // ready to be stopped
139
- if invoc.cmd != daemonCmd {
140
- close(invoc.req.Context().InitDone)
141
- }
142
-
135
// ok, finally, run the command invocation.
136
intrh, ctx := invoc.SetupInterruptHandler(ctx)
137
defer intrh.Close()
@@ -525,15 +517,6 @@ func (i *cmdInvocation) SetupInterruptHandler(ctx context.Context) (io.Closer, c
517
case 1:
518
fmt.Println() // Prevent un-terminated ^C character in terminal
519
528
- ctx := i.req.Context()
529
-
530
- // if we're still initializing, cannot use `ctx.GetNode()`
531
- select {
532
- default: // initialization not done
533
- os.Exit(-1)
534
- case <-ctx.InitDone:
535
- }
536
-
520
ih.wg.Add(1)
521
go func() {
522
defer ih.wg.Done()
commands/request.go
+1
-2
@@ -30,7 +30,6 @@ type Context struct {
30
31
node *core.IpfsNode
32
ConstructNode func() (*core.IpfsNode, error)
33
- InitDone chan bool
33
}
34
35
// 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
287
optDefs = make(map[string]Option)
288
}
289
291
- ctx := Context{Context: context.TODO(), InitDone: make(chan bool)}
290
+ ctx := Context{Context: context.TODO()}
291
values := make(map[string]interface{})
292
req := &request{path, opts, args, file, cmd, ctx, optDefs, values, os.Stdin}
293
err := req.ConvertOptions()