Repository navigation
fix(connectivity_plus): defer Windows COM cleanup to final manager owner - #4009
Open
Adherentman wants to merge 1 commit into
Open
Adherentman wants to merge 1 commit into
Adherentman wants to merge 1 commit into
Conversation
Stop the listener when the plugin is destroyed, but leave COM cleanup to the final shared NetworkManager owner. The event-stream handler can outlive the plugin, and both destructors previously called Cleanup for one Init. Add a standalone native regression using the real plugin and COM apartment. On Windows 10 build 19045, the original source fails with listener_stopped false and CO_E_NOTINITIALIZED (0x800401f0); the patched source passes with listener_stopped true and S_OK. Both Release executables build successfully. Validation: Windows native before/after regression, 16 package Flutter tests, flutter analyze --no-pub, focused clang-format and git diff --check passed.
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.
Description
The Windows plugin and its event-stream handler share a
NetworkManager. The plugin destructor currently callsCleanup()while the stream can still own the manager. When the last owner releases it,NetworkManager::~NetworkManager()callsStopListen()andCleanup()again. This performs twoCoUninitialize()calls for the manager's singleCoInitialize(), prematurely consuming the caller's COM initialization, and releases manager interfaces before the final owner is gone.Change the plugin destructor to stop the listener immediately and let the final shared owner clean up COM once:
StopListen()unregisters the callback and clears the listener state. The manager destructor retains responsibility for COM cleanup. No Dart API, dependency, version, changelog, or other-platform behavior changes.Native regression and before/after results
The new standalone test in
windows/tests/compiles the actual plugin class andNetworkManagerwith the Flutter Windows wrapper; COM and the network listener are real, not mocked. It initializes the caller's apartment, creates the shared plugin/stream ownership, destroys the plugin, checks that its listener has stopped while the manager remains usable, then releases the stream's owner and queries the caller's apartment.On Windows 10 build 19045, MSVC 19.51.36260, Windows SDK 10.0.26100, Flutter 3.47.6, both Release test executables built successfully without compiler warnings/errors. The same test was run against original upstream source (
907994b0e52c2c11ae2f2ccc08d0658e1c73dbaf, matching connectivity_plus 7.3.2) and this patch:false0x800401f0(CO_E_NOTINITIALIZED)true0x0(S_OK)Actual output:
windows/tests/README.mdcontains the exact CMake/CTest commands. The test is independent of production CMake targets and adds no test-framework dependency. Applying the same test to the parent revision reproduces the failure.Additional validation and field context
flutter analyze --no-pub: no issues.flutter test --no-pubin the connectivity_plus package: 16 tests passed.clang-format --dry-run --Werrorandgit diff --check: passed.The investigation started from an exit-time native access violation at a COM
Release()inNetworkManager::Cleanup()during Flutter engine destruction. The test above proves the COM ownership defect and its correction; it does not claim to replay every frame of that production access violation.Upstream CI status (2026-10-23)
The Windows example build and Windows integration test passed on this PR head. The Android integration tests for API 24/29/32/36, Dart analysis, package tests, formatting, and the other completed platform builds also passed. The iOS integration job was still running at this check.
The failing android_example_build job stops while applying the Flutter Gradle plugin: CI installed Flutter 3.47.7 stable, which requires Gradle >= 8.14.0, while the example wrapper pins 8.13. This is a baseline toolchain compatibility failure before application compilation.
The wrapper file is identical in the base revision and this PR (Git blob
3641ebded3581e0db0f4f92917dde8932cf69479). This PR changes only the four Windows source/test files; Android files and workflows are unchanged. The upstream example's Gradle configuration needs a separate compatibility update; repeating the same configuration will not address the version check.Related Issues
Checklist
CHANGELOG.mdnor the plugin version inpubspec.yamlfiles.flutter analyze) does not report any problems on my PR.Breaking Change