Skip to content

test(redis-lua): drop flaky pool.Hits() assertion in VMReuse leak test#583

Merged
bootjp merged 2 commits into
mainfrom
fix/lua-vmreuse-hit-race
Apr 22, 2026
Merged

test(redis-lua): drop flaky pool.Hits() assertion in VMReuse leak test#583
bootjp merged 2 commits into
mainfrom
fix/lua-vmreuse-hit-race

Conversation

@bootjp
Copy link
Copy Markdown
Owner

@bootjp bootjp commented Apr 22, 2026

Summary

Drop the require.GreaterOrEqual(t, pool.Hits(), uint64(1)) line from TestLua_VMReuseDoesNotLeakGlobals. It was flaking on CI (PR #582 run 24781704678), and the assertion is inherently racy on sync.Pool.

Root cause

The assertion required the Script-B pool.get(nil) to return exactly the pooledLuaState that Script-A put back moments earlier. But sync.Pool is documented to discard pooled items under GC pressure, which can easily fire between a Put and a Get on the race runtime. The test's own comment above line 80 already acknowledges this non-determinism — but then the Hits assertion at line 112 reintroduces the same source of flake.

--- FAIL: TestLua_VMReuseDoesNotLeakGlobals (0.00s)
    Error: "0" is not greater than or equal to "1"
    redis_lua_pool_test.go:112

Change

  • Remove the flaky Hits assertion from TestLua_VMReuseDoesNotLeakGlobals.
  • Keep the test's actual purpose intact (no leak of GLOBAL_LEAK, LEAKY_TABLE across pooled states; whitelisted globals still intact).
  • Comment points at TestLua_PoolRecordsReuseVsAllocation which asserts hits + misses deterministically across a controlled loop.

Verification

  • go test -race -count=20 -run TestLua_VMReuseDoesNotLeakGlobals ./adapter/ → 20/20 pass
  • go test -race -count=1 -short ./adapter/... → ok in 63s
  • make lint clean

Pair with PR #582 (multi-exec flake) to unblock the CI pipeline on perf/raft-dispatcher-lanes and fix/idempotent-rollback-marker.

CI on PR #582 failed with:
    --- FAIL: TestLua_VMReuseDoesNotLeakGlobals (0.00s)
        Error: "0" is not greater than or equal to "1"
        redis_lua_pool_test.go:112

The assertion `require.GreaterOrEqual(t, pool.Hits(), uint64(1))`
requires the Script-B `pool.get(nil)` to return the exact
`pooledLuaState` that Script-A put back moments earlier. sync.Pool
is explicitly allowed to evict pooled items under GC pressure
between Put and Get (the comment above line 80 acknowledges this
non-determinism for pointer identity, but then contradicts itself
by asserting a hit counter that has the SAME source of
non-determinism).

Under GHA's -race runtime + whatever GC triggers during the test,
the Script-B Get sometimes returns a fresh allocation (miss), so
Hits() stays at 0 and the assertion fails.

Pool effectiveness already has its own dedicated deterministic
test: TestLua_PoolRecordsReuseVsAllocation asserts
hits + misses across a controlled loop, which is resilient to
sync.Pool eviction. This test is about the security invariant
("no globals leak across pooled states") — the hit counter line
does not contribute to that and only adds flake. Remove it; leave
a comment pointing to the deterministic test.

Verified with `go test -race -count=20 -run
TestLua_VMReuseDoesNotLeakGlobals ./adapter/` 20/20 green and the
full `-short` adapter suite 63s green.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Warning

Rate limit exceeded

@bootjp has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 14 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 7 minutes and 14 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 71b5de81-0494-4fd4-ba6a-da73d13f4112

📥 Commits

Reviewing files that changed from the base of the PR and between e9a2bb9 and b63fa16.

📒 Files selected for processing (1)
  • adapter/redis_lua_pool_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/lua-vmreuse-hit-race

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes a non-deterministic assertion on pool.Hits() in TestLua_VMReuseDoesNotLeakGlobals to prevent CI flakes caused by sync.Pool evictions under GC pressure. Feedback was provided to correct inaccuracies in the added explanatory comment regarding line references and the behavior of related tests, including a suggestion for a more concise and accurate description.

Comment thread adapter/redis_lua_pool_test.go Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@bootjp bootjp merged commit 20f97f4 into main Apr 22, 2026
8 checks passed
@bootjp bootjp deleted the fix/lua-vmreuse-hit-race branch April 22, 2026 13:58
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.

1 participant