fix(connectivity_plus): prevent crash when NetworkManager is unavailable on Linux#3740
Closed
Hovirix wants to merge 1 commit intofluttercommunity:mainfrom
Closed
Conversation
…ble on Linux When NetworkManager is not installed or running on Linux systems, the plugin would crash with an uncaught DBus exception. This affected apps like AppFlowy and others on distributions without NetworkManager or with it disabled. Changes: - Add try-catch blocks to checkConnectivity() and _startListenConnectivity() - Return ConnectivityResult.none when NetworkManager is unavailable - Add explanatory comments about graceful degradation - Add unit tests for NetworkManager unavailable scenarios This ensures the plugin works on all Linux distributions regardless of their network management infrastructure, treating missing NetworkManager as an offline/unknown connectivity state rather than a fatal error. Fixes crashes on NixOS, minimal distributions, and systems with NetworkManager disabled or using alternative network managers (systemd-networkd, ConnMan, etc).
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.
🐛 Bug Fix: Prevent crash when NetworkManager is unavailable on Linux
Fixes a critical crash in
connectivity_pluson Linux systems where NetworkManager is not installed or not running.Problem
Severity: Critical - Application crashes on startup
Platform: Linux only
Trigger: Calling
Connectivity().checkConnectivity()when NetworkManager is unavailableCrash Details
Applications using
connectivity_plus(including AppFlowy and others) crash on Linux systems without NetworkManager with an uncaught platform error:Why this matters: Not all Linux distributions use NetworkManager (some use systemd-networkd, ConnMan, wicd, etc.), and users may have disabled it. The plugin should work gracefully on all Linux configurations.
Solution
Added defensive error handling with try-catch blocks around NetworkManager DBus calls in two critical locations:
1. checkConnectivity() method
[ConnectivityResult.none]when NetworkManager is unavailable2. _startListenConnectivity() method
[ConnectivityResult.none]to the stream when NetworkManager is unavailableBehavior Changes
ConnectivityResult.noneConnectivityResult.noneTesting
New Tests Added
Added 2 unit tests to verify graceful handling:
NetworkManager unavailable - checkConnectivity
connect()checkConnectivity()returns[ConnectivityResult.none]NetworkManager unavailable - onConnectivityChanged
[ConnectivityResult.none]Test Results
✅ All 11 tests pass (9 existing + 2 new)
✅ No breaking changes
✅ Backward compatible
Impact
✅ Benefits
✅ No Breaking Changes
✅ Edge Cases Covered
Files Changed
lib/src/connectivity_plus_linux.darttest/connectivity_plus_linux_test.dartTotal: 2 files changed, 89 insertions(+), 36 deletions(-)
Rationale
Why return
ConnectivityResult.none?Why catch all exceptions?
nmpackageChecklist