mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 19:47:54 +00:00
Receiving a SIGUSR2 makes Vault log the running goroutines' stacks. (#6240)
* Receiving a SIGUSR2 makes Vault log the running goroutines' stacks.
This commit is contained in:
@@ -466,6 +466,7 @@ func initCommands(ui, serverCmdUi cli.Ui, runOpts *RunOptions) {
|
|||||||
PhysicalBackends: physicalBackends,
|
PhysicalBackends: physicalBackends,
|
||||||
ShutdownCh: MakeShutdownCh(),
|
ShutdownCh: MakeShutdownCh(),
|
||||||
SighupCh: MakeSighupCh(),
|
SighupCh: MakeSighupCh(),
|
||||||
|
SigUSR2Ch: MakeSigUSR2Ch(),
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
"ssh": func() (cli.Command, error) {
|
"ssh": func() (cli.Command, error) {
|
||||||
@@ -628,3 +629,20 @@ func MakeSighupCh() chan struct{} {
|
|||||||
}()
|
}()
|
||||||
return resultCh
|
return resultCh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MakeSigUSR2Ch returns a channel that can be used for SIGUSR2
|
||||||
|
// goroutine logging. This channel will send a message for every
|
||||||
|
// SIGUSR2 received.
|
||||||
|
func MakeSigUSR2Ch() chan struct{} {
|
||||||
|
resultCh := make(chan struct{})
|
||||||
|
|
||||||
|
signalCh := make(chan os.Signal, 4)
|
||||||
|
signal.Notify(signalCh, syscall.SIGUSR2)
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
<-signalCh
|
||||||
|
resultCh <- struct{}{}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return resultCh
|
||||||
|
}
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ type ServerCommand struct {
|
|||||||
|
|
||||||
ShutdownCh chan struct{}
|
ShutdownCh chan struct{}
|
||||||
SighupCh chan struct{}
|
SighupCh chan struct{}
|
||||||
|
SigUSR2Ch chan struct{}
|
||||||
|
|
||||||
WaitGroup *sync.WaitGroup
|
WaitGroup *sync.WaitGroup
|
||||||
|
|
||||||
@@ -1262,6 +1263,11 @@ CLUSTER_SYNTHESIS_COMPLETE:
|
|||||||
if err := c.Reload(c.reloadFuncsLock, c.reloadFuncs, c.flagConfigs); err != nil {
|
if err := c.Reload(c.reloadFuncsLock, c.reloadFuncs, c.flagConfigs); err != nil {
|
||||||
c.UI.Error(fmt.Sprintf("Error(s) were encountered during reload: %s", err))
|
c.UI.Error(fmt.Sprintf("Error(s) were encountered during reload: %s", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case <-c.SigUSR2Ch:
|
||||||
|
buf := make([]byte, 32*1024*1024)
|
||||||
|
n := runtime.Stack(buf[:], true)
|
||||||
|
c.logger.Info("goroutine trace", "stack", string(buf[:n]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ func testServerCommand(tb testing.TB) (*cli.MockUi, *ServerCommand) {
|
|||||||
},
|
},
|
||||||
ShutdownCh: MakeShutdownCh(),
|
ShutdownCh: MakeShutdownCh(),
|
||||||
SighupCh: MakeSighupCh(),
|
SighupCh: MakeSighupCh(),
|
||||||
|
SigUSR2Ch: MakeSigUSR2Ch(),
|
||||||
PhysicalBackends: map[string]physical.Factory{
|
PhysicalBackends: map[string]physical.Factory{
|
||||||
"inmem": physInmem.NewInmem,
|
"inmem": physInmem.NewInmem,
|
||||||
"inmem_ha": physInmem.NewInmemHA,
|
"inmem_ha": physInmem.NewInmemHA,
|
||||||
|
|||||||
Reference in New Issue
Block a user