Skip to content
Open
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
2 changes: 1 addition & 1 deletion http/sys_raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func handleSysRaftJoinPost(core *vault.Core, w http.ResponseWriter, r *http.Requ
},
}

joined, err := core.JoinRaftCluster(context.Background(), leaderInfos, req.NonVoter)
joined, err := core.JoinRaftCluster(core.ShutdownContext(), leaderInfos, req.NonVoter)
if err != nil {
respondError(w, http.StatusInternalServerError, err)
return
Expand Down
22 changes: 22 additions & 0 deletions vault/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ type Core struct {
// that the join is complete
raftJoinDoneCh chan struct{}

// shutdownCtx is a context that is canceled when the Core is shut down.
// It is used to scope background operations (such as raft join retries)
// that must not outlive the server process.
shutdownCtx context.Context
shutdownCtxCancel context.CancelFunc

// postUnsealStarted informs the raft retry join routine that unseal key
// validation is completed and post unseal has started so that it can complete
// the join process when Shamir seal is in use
Expand Down Expand Up @@ -1067,6 +1073,8 @@ func CreateCore(conf *CoreConfig) (*Core, error) {
mountsLock := locking.CreateConfigurableRWMutex(detectDeadlocks, "mountsLock")
authLock := locking.CreateConfigurableRWMutex(detectDeadlocks, "authLock")

shutdownCtx, shutdownCtxCancel := context.WithCancel(context.Background())

// Setup the core
c := &Core{
entCore: entCore{},
Expand Down Expand Up @@ -1125,6 +1133,8 @@ func CreateCore(conf *CoreConfig) (*Core, error) {
postUnsealStarted: new(uint32),
raftInfo: new(atomic.Value),
raftJoinDoneCh: make(chan struct{}),
shutdownCtx: shutdownCtx,
shutdownCtxCancel: shutdownCtxCancel,
clusterHeartbeatInterval: clusterHeartbeatInterval,
activityLogConfig: conf.ActivityLogConfig,
billingConfig: conf.BillingConfig,
Expand Down Expand Up @@ -1651,6 +1661,9 @@ func (c *Core) ShutdownCoreError(err error) {
// happens as quickly as possible.
func (c *Core) Shutdown() error {
c.logger.Debug("shutdown called")
if c.shutdownCtxCancel != nil {
c.shutdownCtxCancel()
}
err := c.sealInternal()

c.stateLock.Lock()
Expand Down Expand Up @@ -1679,6 +1692,15 @@ func (c *Core) ShutdownDone() <-chan struct{} {
return c.shutdownDoneCh.Load().(chan struct{})
}

// ShutdownContext returns a context that is canceled when the Core shuts down.
// Use this for background operations that must not outlive the server process.
func (c *Core) ShutdownContext() context.Context {
if c.shutdownCtx == nil {
return context.Background()
}
return c.shutdownCtx
}

// CORSConfig returns the current CORS configuration
func (c *Core) CORSConfig() *CORSConfig {
return c.corsConfig
Expand Down