Skip to content

Benchmark: grafana PR 90939 - #18

Open
celmis-codereviewer wants to merge 1 commit into
cr-base-90939from
cr-pr-90939
Open

celmis-codereviewer wants to merge 1 commit into
cr-base-90939from
cr-pr-90939

Conversation

@celmis-codereviewer

Copy link
Copy Markdown

Benchmark reproduction of grafana#90939

@celmis-codereviewer celmis-codereviewer left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

💬 COMMENT — findings to consider

Full findings and scope are in the review summary comment on this pull request — one persistent comment, updated in place on every run.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

@celmis-codereviewer celmis-codereviewer left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

💬 COMMENT — findings to consider

Full findings and scope are in the review summary comment on this pull request — one persistent comment, updated in place on every run.

if cfg.Env != setting.Dev && ret != nil {
return ret, nil
}
entryPointAssetsCacheMu.Lock()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Why: When concurrent requests call GetWebAssets while entryPointAssetsCache is nil, a goroutine waiting at entryPointAssetsCacheMu.Lock() on line 48 proceeds to re-execute asset loading after acquiring the lock because ret checked on line 45 was evaluated prior to acquiring the write lock and entryPointAssetsCache is not re-checked after being populated by the first goroutine.

🟠 Missing cache re-check after acquiring write lock in double-checked locking pattern

In GetWebAssets, when entryPointAssetsCache is nil, multiple goroutines will fail the initial check at line 45 because ret is nil. The first goroutine acquires entryPointAssetsCacheMu.Lock() at line 48 and populates the cache. However, when subsequent goroutines waiting at line 48 acquire the write lock, they do not inspect entryPointAssetsCache again inside the lock. As a result, they bypass the cache and re-compute assets unnecessarily.

Suggested change
entryPointAssetsCacheMu.Lock()
entryPointAssetsCacheMu.Lock()
defer entryPointAssetsCacheMu.Unlock()
if cfg.Env != setting.Dev && entryPointAssetsCache != nil {
return entryPointAssetsCache, nil
}

agent: defect · rule: defect.missing-check · confidence: 0.95

@celmis-codereviewer

Copy link
Copy Markdown
Author

🤖 Code Review for PR #18

💬 COMMENT — findings to consider

Findings

  • 🟠 Error: 1

Scope

  • Files changed: 1
  • Lines: +13 / -3

Performance

  • Analysis time: 41.8s · agents: structural, cve, contract, security, defect · tokens: 11,251/7,015

Powered by Code Analyzer · context: tree-sitter graph + structural, cve, contract, security, defect

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants