Skip to content

fix(bbr): add read lock to GetBaseModel to prevent concurrent map crash#2570

Merged
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
gyliu513:race
Mar 13, 2026
Merged

fix(bbr): add read lock to GetBaseModel to prevent concurrent map crash#2570
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
gyliu513:race

Conversation

@gyliu513

@gyliu513 gyliu513 commented Mar 13, 2026

Copy link
Copy Markdown
Member
  • GetBaseModel() reads loraAdapterToBaseModel and baseModels maps without holding a lock, while ConfigMapUpdateOrAddIfNotExist() and ConfigMapDelete() write to these maps under ds.lock.Lock(). In Go, concurrent map read and write causes fatal error: concurrent map read and map write, which crashes the process and cannot be recovered.
  • Add ds.lock.RLock()/RUnlock() to GetBaseModel() to ensure safe concurrent access.
  • Add a concurrent read/write test to prevent regression.
  • go test -race ./pkg/bbr/datastore/... test passed.

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

NA

@netlify

netlify Bot commented Mar 13, 2026

Copy link
Copy Markdown

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit 3d31255
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/69b4306c69e22c0008a374d1
😎 Deploy Preview https://deploy-preview-2570--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 13, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Hi @gyliu513. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 13, 2026
@gyliu513

Copy link
Copy Markdown
Member Author

/kind bug

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Mar 13, 2026

@nirrozenbaum nirrozenbaum left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@gyliu513 nice catch!
Thanks! 🙏🏼

/ok-to-test
/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 13, 2026
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 13, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gyliu513, nirrozenbaum

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 13, 2026
@gyliu513

Copy link
Copy Markdown
Member Author

/retest

- `GetBaseModel()` reads `loraAdapterToBaseModel` and `baseModels` maps without
  holding a lock, while `ConfigMapUpdateOrAddIfNotExist()` and `ConfigMapDelete()`
  write to these maps under `ds.lock.Lock()`. In Go, concurrent map read and write
  causes `fatal error: concurrent map read and map write`, which crashes the
  process and cannot be recovered.
- Add `ds.lock.RLock()`/`RUnlock()` to `GetBaseModel()` to ensure safe concurrent
  access.
- Add a concurrent read/write test to prevent regression.
- go test -race ./pkg/bbr/datastore/... test passed.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 13, 2026

go func() {
for i := 0; i < 10000; i++ {
_ = ds.ConfigMapUpdateOrAddIfNotExist(cm)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

linter is unhappy when ignoring the error.
maybe add err := ..
and assert.NoError(..)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I should run make ci-lint, it should be working now, thanks @nirrozenbaum

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@nirrozenbaum , my previous code is just ds.ConfigMapUpdateOrAddIfNotExist(cm) and this makes CI not happy, updating to _ = ds.ConfigMapUpdateOrAddIfNotExist(cm) is good enough to fix the lint error, hope this is ok.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sure. as long as the linter is happy, I'm happy 😄

@nirrozenbaum

Copy link
Copy Markdown
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 13, 2026
@k8s-ci-robot
k8s-ci-robot merged commit fab1af6 into kubernetes-sigs:main Mar 13, 2026
11 checks passed
@gyliu513
gyliu513 deleted the race branch March 13, 2026 16:08
BizerNotNull pushed a commit to BizerNotNull/gateway-api-inference-extension that referenced this pull request Mar 15, 2026
…sh (kubernetes-sigs#2570)

- `GetBaseModel()` reads `loraAdapterToBaseModel` and `baseModels` maps without
  holding a lock, while `ConfigMapUpdateOrAddIfNotExist()` and `ConfigMapDelete()`
  write to these maps under `ds.lock.Lock()`. In Go, concurrent map read and write
  causes `fatal error: concurrent map read and map write`, which crashes the
  process and cannot be recovered.
- Add `ds.lock.RLock()`/`RUnlock()` to `GetBaseModel()` to ensure safe concurrent
  access.
- Add a concurrent read/write test to prevent regression.
- go test -race ./pkg/bbr/datastore/... test passed.
nirrozenbaum pushed a commit to llm-d/llm-d-inference-payload-processor that referenced this pull request Apr 28, 2026
…sh (kubernetes-sigs/gateway-api-inference-extension#2570)

- `GetBaseModel()` reads `loraAdapterToBaseModel` and `baseModels` maps without
  holding a lock, while `ConfigMapUpdateOrAddIfNotExist()` and `ConfigMapDelete()`
  write to these maps under `ds.lock.Lock()`. In Go, concurrent map read and write
  causes `fatal error: concurrent map read and map write`, which crashes the
  process and cannot be recovered.
- Add `ds.lock.RLock()`/`RUnlock()` to `GetBaseModel()` to ensure safe concurrent
  access.
- Add a concurrent read/write test to prevent regression.
- go test -race ./pkg/bbr/datastore/... test passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants