Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SemaphoreLock context.Context implementation #52046

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

GavinFrazar
Copy link
Contributor

@GavinFrazar GavinFrazar commented Feb 12, 2025

This updates SempahoreLock to embed its context.Context and use WithCancelCause for its cancellation func, so that it properly implements the context.Context interface.
Specifically, the Err() method of a context.Context must not return a nil error if its Done channel has closed.

Fixes a panic that occurs if context.WithCancel(lease) is called after the lease context is done.
See: https://github.com/gravitational/teleport/actions/runs/13255328689/job/37001102495?pr=52023

{"timestamp":"2025-02-11T03:41:14Z","level":"debug","caller":"retryutils/retry.go:193","message":"Waiting to retry operation again","wait":826308778,"error":"cannot acquire semaphore user_task/deb47f2c-cfef-5b4d-bd50-15ed83d48e2d (err-max-leases)"}
{"timestamp":"2025-02-11T03:41:14Z","level":"warning","caller":"discovery/status.go:729","message":"Failed to create discover eks user task","component":"discovery:service","integration":"my-integration","issue_type":"eks-cluster-unreachable","aws_account_id":"123456789012","aws_region":"us-west-2","error":"context canceled"}
panic: context: internal error: missing cancel error

goroutine 6143 [running]:
context.(*cancelCtx).cancel(0xc002523b80, 0x0, {0x0, 0x0}, {0x1213ba00, 0x17048650})
	/opt/go/src/context/context.go:538 +0x346
context.(*cancelCtx).propagateCancel(0xc002523b80, {0x122031b8, 0xc007504d80}, {0x12174528, 0xc002523b80})
	/opt/go/src/context/context.go:473 +0x2c5
context.withCancel(...)
	/opt/go/src/context/context.go:273
context.WithCancel({0x122031b8, 0xc007504d80})
	/opt/go/src/context/context.go:236 +0xb1
github.com/gravitational/teleport/lib/srv/discovery.(*Server).acquireSemaphoreForUserTask(0xc008072708, {0xc008697a70, 0x24})
	/__w/teleport/teleport/lib/srv/discovery/status.go:609 +0x44c
github.com/gravitational/teleport/lib/srv/discovery.(*Server).mergeUpsertDiscoverEKSTask(0xc008072708, {{0xc00780cee2, 0xe}, {0x11226b9b, 0x17}, {0x113092c9, 0xc}, {0x113092bf, 0x9}, 0x0}, ...)
	/__w/teleport/teleport/lib/srv/discovery/status.go:760 +0x285
github.com/gravitational/teleport/lib/srv/discovery.(*Server).upsertTasksForAWSEKSFailedEnrollments(0xc008072708)
	/__w/teleport/teleport/lib/srv/discovery/status.go:728 +0x2bd
github.com/gravitational/teleport/lib/srv/discovery.(*Server).enrollEKSClusters(0xc008072708, {0x113092bf, 0x9}, {0xc00780cee2, 0xe}, {0xc004e12d80, 0x24}, {0xc000c98240, 0x2, 0x2}, ...)
	/__w/teleport/teleport/lib/srv/discovery/kube_integration_watcher.go:318 +0x1ae6
created by github.com/gravitational/teleport/lib/srv/discovery.(*Server).startKubeIntegrationWatchers.func2 in goroutine 5320
	/__w/teleport/teleport/lib/srv/discovery/kube_integration_watcher.go:185 +0x154e

This updates SempahoreLock to embed its context.Context and use
WithCancelCause for its cancellation func, so that it properly
implements the context.Context interface.
Specifically, the Err() method of a context.Context must not return a
nil error if its Done channel has closed.
@GavinFrazar GavinFrazar added no-changelog Indicates that a PR does not require a changelog entry backport/branch/v15 backport/branch/v16 backport/branch/v17 labels Feb 12, 2025
@GavinFrazar GavinFrazar marked this pull request as ready for review February 12, 2025 02:50
@GavinFrazar GavinFrazar requested a review from tigrato February 12, 2025 02:51
@GavinFrazar GavinFrazar added this pull request to the merge queue Feb 12, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 12, 2025
@GavinFrazar GavinFrazar added this pull request to the merge queue Feb 12, 2025
Merged via the queue into master with commit dc1055b Feb 12, 2025
47 checks passed
@GavinFrazar GavinFrazar deleted the gavinfrazar/fix-semaphore-lock-cancel-panic branch February 12, 2025 21:38
@public-teleport-github-review-bot

@GavinFrazar See the table below for backport results.

Branch Result
branch/v15 Failed
branch/v16 Failed
branch/v17 Create PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants