Skip to content
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
25 changes: 23 additions & 2 deletions cmd/dmsg/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package commands

import (
"fmt"
"os"
"os/signal"
"syscall"

"github.com/skycoin/skywire/pkg/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire/pkg/skywire-utilities/pkg/calvin"
Expand All @@ -24,8 +27,9 @@ import (
)

var (
bv bool
dbi bool
bv bool
dbi bool
withKill bool
)

func init() {
Expand Down Expand Up @@ -63,6 +67,8 @@ func init() {
di.RootCmd.Use = "ip"

modifySubcommands(RootCmd)
RootCmd.PersistentFlags().BoolVar(&withKill, "with-kill", false, "force exit after 3 interrupt signals")
RootCmd.PersistentFlags().MarkHidden("with-kill") //nolint:errcheck,gosec
if fmt.Sprintf("%v", buildinfo.DebugBuildInfo()) != "" {
RootCmd.Flags().BoolVarP(&dbi, "info", "d", false, "print runtime/debug.BuildInfo")
}
Expand Down Expand Up @@ -98,6 +104,21 @@ var RootCmd = &cobra.Command{
}
return ret
}(),
PersistentPreRun: func(_ *cobra.Command, _ []string) {
if withKill {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
sigCount := 0
for range c {
sigCount++
if sigCount >= 3 {
os.Exit(1)
}
}
}()
}
},
SilenceErrors: true,
SilenceUsage: true,
DisableSuggestions: true,
Expand Down
7 changes: 6 additions & 1 deletion pkg/dmsg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,12 @@ func (ce *Client) Close() error {
ce.sessionsMx.Unlock()
ce.porter.CloseAll(ce.log)
ce.wg.Wait()
err = ce.EntityCommon.delEntry(context.Background())
// Use a short timeout for discovery cleanup — if the discovery
// server is accessed over dmsg (which we just closed), this
// request would hang forever with context.Background().
delCtx, delCancel := context.WithTimeout(context.Background(), 5*time.Second)
err = ce.EntityCommon.delEntry(delCtx)
delCancel()
})
return err
}
Expand Down
Loading