fix: evict failed compilation from cache to allow retry - #470
Open
chenjunwenhao wants to merge 1 commit into
Open
fix: evict failed compilation from cache to allow retry#470chenjunwenhao wants to merge 1 commit into
chenjunwenhao wants to merge 1 commit into
Conversation
When a script fails to compile with QLOptions.cache(true), the failed FutureTask was permanently cached, preventing any subsequent retry from ever succeeding. Now the failed future is evicted from the cache so that the next call can attempt fresh compilation. Uses conditional remove (ConcurrentHashMap.remove(key, value)) to avoid accidentally evicting a replacement future inserted by another thread between the failure and the eviction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
QLOptions.cache(true)is enabled and a script fails to compile (e.g., syntax error), the failedFutureTaskis permanently cached incompileCache. All subsequent calls with the same script will get the same cached failure, even if the root cause has been resolved (e.g., a missing class becomes available).Future.get()throws, so the next call can attempt fresh compilation.Root Cause
In
Express4Runner.getParseFuture(), aFutureTaskis inserted into theConcurrentHashMapviaputIfAbsentbeforeparseTask.run()executes. IfparseDefinition(script)throws, theFutureTaskcaptures the exception internally and remains in the cache. Every subsequent call finds this poisoned future and re-throws the sameExecutionExceptionforever.The only existing workaround is
clearCompileCache(), which drops all cached scripts (including successfully compiled ones), causing a latency spike.Fix
Uses conditional
remove(key, value)to safely evict only the specific failed future, avoiding accidental eviction of a replacement that another thread may have inserted concurrently.Test Plan
compileCacheEvictsFailedEntriesTest: Verifies a failed compilation doesn't prevent subsequent valid scripts from compiling with cache enabled.compileCacheDoesNotLeakFailedEntriesTest: Verifies multiple distinct failing scripts don't leak entries, and valid scripts still work and are cacheable.concurrentCacheTestcontinues to pass.