Skip to content

Commit a04cad4

Browse files
committed
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.
1 parent d786383 commit a04cad4

File tree

3 files changed

+1
-22
lines changed

3 files changed

+1
-22
lines changed

cmd/ipfs/daemon.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,6 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
288288
corehttp.VersionOption(),
289289
}
290290

291-
// our global interrupt handler can now try to stop the daemon
292-
close(req.Context().InitDone)
293-
294291
if rootRedirect != nil {
295292
opts = append(opts, rootRedirect)
296293
}

cmd/ipfs/main.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,6 @@ func main() {
133133
os.Exit(1)
134134
}
135135

136-
// our global interrupt handler may try to stop the daemon
137-
// before the daemon is ready to be stopped; this dirty
138-
// workaround is for the daemon only; other commands are always
139-
// ready to be stopped
140-
if invoc.cmd != daemonCmd {
141-
close(invoc.req.Context().InitDone)
142-
}
143-
144136
// ok, finally, run the command invocation.
145137
intrh, ctx := invoc.SetupInterruptHandler(ctx)
146138
defer intrh.Close()
@@ -518,15 +510,6 @@ func (i *cmdInvocation) SetupInterruptHandler(ctx context.Context) (io.Closer, c
518510
case 1:
519511
fmt.Println() // Prevent un-terminated ^C character in terminal
520512

521-
ctx := i.req.Context()
522-
523-
// if we're still initializing, cannot use `ctx.GetNode()`
524-
select {
525-
default: // initialization not done
526-
os.Exit(-1)
527-
case <-ctx.InitDone:
528-
}
529-
530513
ih.wg.Add(1)
531514
go func() {
532515
defer ih.wg.Done()

commands/request.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ type Context struct {
3030

3131
node *core.IpfsNode
3232
ConstructNode func() (*core.IpfsNode, error)
33-
InitDone chan bool
3433
}
3534

3635
// 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
288287
optDefs = make(map[string]Option)
289288
}
290289

291-
ctx := Context{Context: context.TODO(), InitDone: make(chan bool)}
290+
ctx := Context{Context: context.TODO()}
292291
values := make(map[string]interface{})
293292
req := &request{path, opts, args, file, cmd, ctx, optDefs, values, os.Stdin}
294293
err := req.ConvertOptions()

0 commit comments

Comments
 (0)