Skip to content

fix(connectivity_plus): prevent Linux client leaks#3929

Open
Kibiandkimi wants to merge 1 commit into
fluttercommunity:mainfrom
Kibiandkimi:fix/connectivity-linux-listener-lifecycle
Open

fix(connectivity_plus): prevent Linux client leaks#3929
Kibiandkimi wants to merge 1 commit into
fluttercommunity:mainfrom
Kibiandkimi:fix/connectivity-linux-listener-lifecycle

Conversation

@Kibiandkimi

Copy link
Copy Markdown

Description

Fix the Linux NetworkManagerClient lifecycle when connectivity listeners are canceled and immediately re-subscribed.

StreamController.broadcast does not wait for an asynchronous onCancel callback. The previous implementation accessed the shared _client on both sides of await calls, so a new listener could reuse a client that was still closing, while an older listener setup could later dereference a cleared client. Closing a NetworkManagerClient before its pending connection finishes can also leave the subsequently opened system D-Bus connection unclosed. In addition, the propertiesChanged subscription was not retained or canceled.

This change:

  • owns each client, connection future, and property subscription in one session;
  • detaches the current session synchronously before asynchronous cleanup;
  • waits for an in-flight connection before closing its client;
  • ignores callbacks from stale sessions and cancels property subscriptions;
  • closes one-shot clients in checkConnectivity on error paths as well.

The regression tests deterministically cover error cleanup, property-subscription cleanup, and cancellation/re-subscription while a connection is pending.

Related Issues

None.

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

Validation

  • Scoped formatting check for all connectivity_plus packages
  • Scoped analyzer for connectivity_plus, connectivity_plus_platform_interface, and the example
  • Unit tests for connectivity_plus and connectivity_plus_platform_interface
  • Linux example debug build
  • Linux NetworkManager integration smoke test

Track each NetworkManager client and its property subscription as one session. Detach sessions synchronously on cancellation, wait for in-flight connects before closing, and close temporary clients on errors.

Add regression tests for error cleanup, subscription cancellation, and rapid resubscription.
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.

1 participant