Skip to content

raft: scope join retry context to core shutdown lifecycle#31806

Open
1seal wants to merge 1 commit intohashicorp:mainfrom
1seal:scope-raft-join-retry-context
Open

raft: scope join retry context to core shutdown lifecycle#31806
1seal wants to merge 1 commit intohashicorp:mainfrom
1seal:scope-raft-join-retry-context

Conversation

@1seal
Copy link
Contributor

@1seal 1seal commented Feb 26, 2026

summary

  • scope raft join retry goroutines to the core shutdown lifecycle by passing a shutdown-scoped context into JoinRaftCluster.

background

/v1/sys/storage/raft/join currently passes context.Background() into JoinRaftCluster. when retry=true, JoinRaftCluster may spawn a retry loop that checks ctx.Done() but will never observe cancellation.

this change adds Core.ShutdownContext() (canceled in Core.Shutdown()) and uses it in the raft join http handler, so retries are stopped automatically when the core is shutting down.

testing

  • go test ./http/... -run TestNonExistent
  • go test ./vault/... -run TestNonExistent

The raft join HTTP handler passes context.Background() into JoinRaftCluster. When retry=true, this can spawn a background retry goroutine that cannot be canceled, because the context never finishes.

Add a shutdown-scoped context to Core that is canceled in Core.Shutdown(), and use it in the raft join HTTP handler so that join retry goroutines are automatically stopped when the core shuts down.

The config-based retry_join path (InitiateRetryJoin) already receives a properly scoped context from the server command, so it is not affected.
@1seal 1seal requested a review from a team as a code owner February 26, 2026 19:51
@1seal 1seal requested a review from kubawi February 26, 2026 19:51
@vercel
Copy link

vercel bot commented Feb 26, 2026

@1seal is attempting to deploy a commit to the HashiCorp Team on Vercel.

A member of the Team first needs to authorize it.

@hashicorp-cla-app
Copy link

hashicorp-cla-app bot commented Feb 26, 2026

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app
Copy link

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@heatherezell heatherezell added storage/raft bug Used to indicate a potential bug labels Mar 12, 2026
Copy link
Contributor Author

@1seal 1seal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the review — good call to check.

ShutdownCoreError already routes through Shutdown via ShutdownWait:

func (c *Core) ShutdownCoreError(err error) {
    c.Logger().Error("shutting down core", "error", err)
    if shutdownErr := c.ShutdownWait(); shutdownErr != nil { // ← calls Shutdown()
        ...
    }
}

so shutdownCtxCancel() fires on that path too — no additional wiring needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Used to indicate a potential bug storage/raft

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants