Skip to content

[pigeon] Fix race in event channel handler removal integration test - #13528

Merged
auto-submit[bot] merged 1 commit into
flutter:mainfrom
mmohankrishna-lab:fix-pigeon-event-channel-removal-flake
Nov 2, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:mainfrom
mmohankrishna-lab:fix-pigeon-event-channel-removal-flake

Conversation

@mmohankrishna-lab

@mmohankrishna-lab mmohankrishna-lab commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

This PR fixes the tree. Linux_android custom_package_tests master is failing on main (all 3 attempts of #4084) in the Pigeon integration test event channels handle multiple instances:

The following MissingPluginException was thrown while de-activating platform stream on channel
dev.flutter.pigeon.pigeon_integration_tests.EventChannelMethods.streamConsistentNumbers.1:
MissingPluginException(No implementation found for method cancel on channel
dev.flutter.pigeon.pigeon_integration_tests.EventChannelMethods.streamConsistentNumbers.1)

Cause

The test plugin unregisters the stream handler for instance "1" (to exercise event channel unregistration, added in #13438) immediately after calling endOfStream(). On the Dart side, the end of the stream closes the EventChannel's broadcast stream, which then sends a cancel method call back on the same channel. If the handler has already been removed by the time that cancel call arrives, it fails with a MissingPluginException, which fails the test. Whether it fails depends on timing, so it shows up as a flake.

Fix

Unregister the handler from the stream handler's onCancel instead, i.e. only after the cancel call has been received, in both the Kotlin (Android) and Swift (iOS/macOS) test plugins. The generated Pigeon stream handler wrappers already forward the platform onCancel to the user handler, so no generator or generated-code changes are needed. The test still exercises unregistration; it just no longer races with the channel teardown.

This only changes test plugin code under platform_tests/, so there is no change to the published package.

Testing

On an Android emulator (Pixel 9a), running only event channels handle multiple instances:

Runs Failures (MissingPluginException on cancel)
Without this fix (main) 5 2
With this fix 10 0

The full android_kotlin_integration_tests suite (680 tests) also passes with this fix, as do dart_unittests and flutter_unittests. The Swift change mirrors the Kotlin one and is covered by the iOS/macOS integration tests in CI.

Related

flutter/flutter#179154 tracks a different flake in the same test on macOS Swift (Bad state: Cannot add new events after calling close, i.e. an event sent after endOfStream). This PR does not address that one, and the macOS Swift skip is left in place.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

The test plugin removed the stream handler for instance "1" immediately after calling endOfStream. Closing the stream makes the Dart side send a "cancel" call on the channel, which then raced with the removal and failed with a MissingPluginException, closing the tree.

Remove the handler from onCancel instead, after the "cancel" call has been received.

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

Copy link
Copy Markdown
Contributor

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 modifies the Android and iOS test plugins to handle stream cancellation instead of stream completion. In both Kotlin and Swift implementations, the onCompleted callbacks are replaced with onCancelled callbacks, and the stream handler removal is moved to the onCancel method to prevent a race condition with the Dart-side cancel call. There are no review comments, and I have no feedback to provide.

@mmohankrishna-lab

Copy link
Copy Markdown
Contributor Author

@tarrinneal @stuartmorgan-g This fixes the current tree breakage in Linux_android custom_package_tests master (the flaky event channels handle multiple instances test added with #13438). All presubmits are green. PTAL when you have a moment.

@elliette
elliette self-requested a review November 2, 2026 17:28

@elliette elliette left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving on behalf of Plugins gardener rotation, this fixes flutter/flutter#195804 which is breaking flutter -> packages autorolls.

@elliette

elliette commented Nov 2, 2026

Copy link
Copy Markdown
Member

This also fixes the tree breakage, adding emergency label.

@elliette elliette added emergency Override tree-status signal (land even with closed tree), combine with the autosubmit label. autosubmit Merge PR when tree becomes green via auto submit App labels Nov 2, 2026
@flutter-dashboard

Copy link
Copy Markdown

Detected the emergency label.

If you add the autosubmit label, the bot will wait until all presubmits pass but ignore the tree status, allowing fixes for tree breakages while still validating that they don't break any existing presubmits.

The "Merge" button is also unlocked. To bypass presubmits as well as the tree status, press the GitHub "Add to Merge Queue".

@auto-submit
auto-submit Bot merged commit a378299 into flutter:main Nov 2, 2026
11 of 12 checks passed
@elliette

elliette commented Nov 2, 2026

Copy link
Copy Markdown
Member

Thank you for the fix @mmohankrishna-lab! It was great to find this already fixed this morning.

RamyAkin pushed a commit to RamyAkin/flutter that referenced this pull request Nov 3, 2026
flutter/packages@3f34a6f...1df8447

2026-11-03 [email protected] [webview_flutter] Convert iOS impl
example app to Swift (flutter/packages#13538)
2026-11-03 [email protected] [material_ui]
Temporarily exclude material_ui from non-Wasm web unit tests
(flutter/packages#13537)
2026-11-02 [email protected] [material_ui]
Removes list semantics in some a11y_assessment samples
(flutter/packages#13257)
2026-11-02 [email protected] [material_ui] Use named uniforms
instead of setFloat in InkSparkle (flutter/packages#13445)
2026-11-02 [email protected] [VPAT] Fix contrast and reflow in
three a11y_assessments demos (flutter/packages#13409)
2026-11-02 [email protected]
[two_dimensional_scrollables] Fix pinned cells hit test
(flutter/packages#13376)
2026-11-02 [email protected] [tool] Let the OS pick a port for
chromedriver and wait for exit (flutter/packages#13355)
2026-11-02 [email protected] [vector_graphics] Draw <text> under an RTL ambient
direction (flutter/packages#13408)
2026-11-02 [email protected] [VPAT] Keep a11y_assessments
snackbars open until closed (flutter/packages#13451)
2026-11-02 [email protected] [pigeon] Fix race in event channel
handler removal integration test (flutter/packages#13528)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD emergency Override tree-status signal (land even with closed tree), combine with the autosubmit label. p: pigeon platform-android platform-ios platform-macos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants