Skip to content

Fix flaky ensureCleanUpAddonCleansUp by holding CleanupAddon strongly#3896

Merged
vogella merged 1 commit into
eclipse-platform:masterfrom
vogella:fix/cleanup-addon-gc-flake
Apr 17, 2026
Merged

Fix flaky ensureCleanUpAddonCleansUp by holding CleanupAddon strongly#3896
vogella merged 1 commit into
eclipse-platform:masterfrom
vogella:fix/cleanup-addon-gc-flake

Conversation

@vogella
Copy link
Copy Markdown
Contributor

@vogella vogella commented Apr 16, 2026

Summary

PartRenderingEngineTests.ensureCleanUpAddonCleansUp has been flaking for a long time (#3581). Prior fixes (synchronous cleanup; extra spinEventLoop() between hides) addressed wrong root causes — the synchronous fix had to be reverted because it broke the Welcome screen (#3784), and the event-loop fix did not stop the flake.

Root cause

The test creates the addon via ContextInjectionFactory.make(CleanupAddon.class, appContext) and discards the returned reference. The DI framework holds injected objects only via WeakReference (see InjectorImpl.injectedObjects). When GC collects the addon between event registration and event firing, the @UIEventTopic dispatcher (UIEventObjectSupplier.UIEventHandler.handleEvent) observes requestor.isValid() == false and silently unsubscribes — the addon method is never invoked, the asyncExec that would have unrendered the part stack is never queued, and the assertion fails.

Reproduced locally on Linux with the test trace clearly showing the TBR partStackBC -> false event missing on every failure.

Fix

Store the addon in the application context. The context holds it strongly for the test lifetime; this also matches how addons are referenced in real applications (via the application model). The same pattern is applied to testBug332463 and CleanupAddonTest, which had the same latent issue.

CI verification

A previous revision of this PR wrapped the test in @RepeatedTest(500) to run it 500 times across all CI platforms — all green. Locally (Linux) before the fix: ~1.2% failure rate over 500 iterations; with the fix: 500/500 passed. The @RepeatedTest(500) annotation has now been removed and the test is back to a single @Test, ready for merge.

Fixes #3581

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 16, 2026

Test Results

   852 files  ±0     852 suites  ±0   53m 53s ⏱️ + 2m 3s
 7 894 tests ±0   7 651 ✅ ±0  243 💤 ±0  0 ❌ ±0 
20 184 runs  ±0  19 529 ✅ ±0  655 💤 ±0  0 ❌ ±0 

Results for commit 5cd5011. ± Comparison against base commit 258b96d.

♻️ This comment has been updated with latest results.

@vogella
Copy link
Copy Markdown
Contributor Author

vogella commented Apr 16, 2026

@ptziegler looks like we finally nailed it. For tip that you could reproduce the test failure if you run the test 100 times was the golden nugget which helped to solve this.

The test created the CleanupAddon via ContextInjectionFactory.make(...)
without keeping the returned reference. The DI framework only holds
injected objects via WeakReference (InjectorImpl.injectedObjects), so
GC could collect the addon between event registration and event firing.
Once collected, the @UIEventTopic handler observed
requestor.isValid() == false and silently unsubscribed without invoking
the addon's method. The asyncExec that would have set partStack
toBeRendered=false was never queued, leaving the assertion to fail.

Storing the addon in the application context keeps a strong reference
for the lifetime of the test, matching how addons are referenced in
production via the application model.

Reproduced locally (Linux, DISPLAY=:1) at ~1.2% failure rate over 500
iterations of the test. With the fix, 500 iterations all pass. CI also
ran the test 500 times across all platforms (green) before this commit
removed the temporary @RepeatedTest(500) annotation.

The same pattern is applied to testBug332463 and CleanupAddonTest,
which had the same latent issue.

Refs eclipse-platform#3581
@vogella vogella force-pushed the fix/cleanup-addon-gc-flake branch from 9216956 to 5cd5011 Compare April 16, 2026 18:49
@vogella vogella marked this pull request as ready for review April 16, 2026 18:49
@vogella vogella merged commit 1146cf2 into eclipse-platform:master Apr 17, 2026
18 checks passed
@vogella vogella deleted the fix/cleanup-addon-gc-flake branch April 17, 2026 03:20
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.

PartRenderingEngineTests.ensureCleanUpAddonCleansUp still fails randomly

1 participant