Repository navigation
Fix two real double-release causes in CefClient/render_handler (issue #22) - #42
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #42 +/- ##
============================================
- Coverage 38.01% 38.01% -0.01%
Complexity 735 735
============================================
Files 243 243
Lines 14863 14866 +3
Branches 2449 2449
============================================
+ Hits 5650 5651 +1
Misses 8011 8011
- Partials 1202 1204 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Sep 5, 2026
Thrameos
added a commit
that referenced
this pull request
Sep 5, 2026
preliminary update racing ahead of onBeforeDownload CefDownloadItemTest.cancelDuringDownloadInvokesNCancel() flaked intermittently in CI across multiple unrelated backport PRs (#38, #39, #41, #42), always failing the same assertion: "onBeforeDownload was never invoked". Root-caused by reproducing it locally (100% deterministic once a low-risk, narrowly-scoped repro was possible -- see PR #44's run_tests.sh fix, needed first to run just this one test without also running the whole suite + leak-sweep) and adding temporary native fprintf instrumentation (not included in this commit) at DownloadHandler::OnBeforeDownload/ OnDownloadUpdated and ClientHandler::GetDownloadHandler. That instrumentation showed CEF can deliver a preliminary OnDownloadUpdated() notification -- for a valid, real CefDownloadItem -- *before* OnBeforeDownload() has been dispatched to the handler at all. This test's onDownloadUpdated() used to treat "not complete" on the very first update it saw as "must actively cancel it", immediately calling callback.cancel() and terminateTest() -- racing ahead of onBeforeDownload and ending the test before it ever got a chance to run, which is exactly what "onBeforeDownload was never invoked" captures. Fix: ignore any onDownloadUpdated() notification that arrives before this handler's own onBeforeDownload() has recorded its decision (gotBeforeDownload[0]). Verified via direct reproduction: failed 3/3 in isolation before the fix (including against a heavily-used local CEF profile where it failed 100% of the time), passed cleanly every time after (5+ consecutive solo runs, plus the full class together) with no change to downloadCompletesAndWritesRealFile's behavior. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HBFmQs6JDypYP5qdC99yDq
1. CefClient.cleanupBrowser()'s "close all" branch iterated browser_.values() directly while browsers concurrently removed themselves from the same map (browser.close(true) synchronously triggers onBeforeClose() -> cleanupBrowser() -> browser_.remove()), risking ConcurrentModificationException. Snapshot into an ArrayList before iterating. 2. cleanupBrowser()'s remove*Handler() teardown block could re-enter once browser_ had already emptied out and isDisposed_ was already true, double-releasing each handler's native reference a second time. Added a handlersRemoved_ guard so the block only runs once. 3. RenderHandler::GetJNIScreenInfo() double-wrapped the caller-owned jScreenInfo parameter in a second ScopedJNIObjectLocal, causing a double DeleteLocalRef on the same jobject. Ported from coverage/phase1-value-objects-phase2-handlers's 7290b2e, which found and confirmed all three live via JCEF_TRACE (a tracing facility that only exists on that branch, not master -- the trace calls and the JCefTrace import are dropped here since they'd need issue #26's not-yet-backported facility). See issue #22. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01HBFmQs6JDypYP5qdC99yDq
Thrameos
force-pushed
the
backport/cleanupbrowser-double-release
branch
from
September 5, 2026 21:23
7e3c504 to
2a721f4
Compare
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
CefClient.cleanupBrowser()'s "close all" branch iteratedbrowser_.values()directly whilebrowser.close(true)synchronously re-entered and mutated the same map viaonBeforeClose()->cleanupBrowser()->browser_.remove(). Snapshot into anArrayListbefore iterating.cleanupBrowser()'s handler-removal +super.dispose()block could re-enter oncebrowser_was already empty andisDisposed_was already true, double-releasing each handler's native reference. Added ahandlersRemoved_guard so it only runs once.RenderHandler::GetJNIScreenInfo()wrapped the caller-ownedjScreenInfoparameter in a secondScopedJNIObjectLocal, causing a doubleDeleteLocalRefon the samejobject(undefined behavior per the JNI spec).Ported from
coverage/phase1-value-objects-phase2-handlers's7290b2e, which found and confirmed all three live via that branch'sJCEF_TRACEfacility (tracing observed the exact sameCefFocusHandlernative pointer released twice, ~83ms apart, with no interveningAddRef). The trace calls andJCefTraceimport are dropped here since master doesn't have that tracing facility yet (issue #26, not backported).Closes #22 (partially -- the source commit's own message notes a second, distinct double-release mechanism, suspected in
ClientHandler::GetHandler<T>()'s reentrant lazy-create cache, that remains open and unfixed).Test plan
ninja jcef) and Java (tools/compile.sh linux64) both build clean.testjob) to verify instead.🤖 Generated with Claude Code