-
-
Notifications
You must be signed in to change notification settings - Fork 230
Fix: Add Fallback in ExpressionPromoter to Handle Cache Cleanup in ConstantExpressionHelper #905
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
base: master
Are you sure you want to change the base?
Fix: Add Fallback in ExpressionPromoter to Handle Cache Cleanup in ConstantExpressionHelper #905
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
When I just copy this test to the master branch, it does not fail, can you double check if this test actually tests this exact scenario?
-
The fix is limited to 1 place, but the ConstantExpressionHelper is used in multiple places.
I was just wondering, would setting ReturnExpiredItems to true also solve this issue in all places?
Oh, you are right. When running the tests all together, it didn't fail, but when running only once, it failed. Here is why: The issue is that Since the To make tests isolated, we use reflection to overwrite var field = typeof(ConstantExpressionHelperFactory)
.GetField("_instance", BindingFlags.NonPublic | BindingFlags.Static);
field?.SetValue(null, new ConstantExpressionHelper(parsingConfig)); This ensures each test has its own independent About the |
any updates on this? thanks |
🧩 Problem Summary
In multi-threaded scenarios, a race condition can occur due to the internal behavior of
SlidingCache
used inConstantExpressionHelper
. Specifically:CreateLiteral(value, text)
, both_expressions
and_literals
caches are populated._literals
is cleaned up (due to TTL or cleanup frequency),ExpressionPromoter.Promote()
will fail to retrieve the text representation of the constant.This issue was especially noticeable when comparing expressions like:
✅ What This PR Does
This PR adds a safe fallback mechanism in
ExpressionPromoter.Promote()
:_constantExpressionHelper.TryGetText(...)
fails (because_literals
was cleaned),ce.Value?.ToString()
to obtain a text representation for parsing.This ensures the parser remains robust and consistent, even when cache entries are removed in the background.
🧪 How We Reproduced the Issue
A unit test was created to simulate this scenario by:
CreateLiteral(...)
._literals
entry.Promote()
after cleanup.📈 Impact
ExpressionPromoter
safer and more fault-tolerant.🚀 Ready for Review
Let me know if there are preferences for making the fallback smarter (e.g. re-adding the literal to cache or applying type suffixes). This version keeps it simple and safe.