Skip to content

Commit

Permalink
Give network monitor time to figure things out
Browse files Browse the repository at this point in the history
Inside flatpak network monitor starts out assuming that it's
disconnected, and then makes an async call to the portal to get the
current state of affairs.

Hence, if we check connectivity right after constructing the default
monitor instance we're caught in the initial state and never see the
actual state of the network.

To work around this just wait for 0.5s and hope that network monitor
figured things out by then.

The proper way would be to listen for the notify::connectivity signal,
but that's a tad more complicated to get right, and seems like overkill
for a debug report.

See https://gitlab.gnome.org/GNOME/glib/-/issues/1718 for background.
  • Loading branch information
swsnr committed Nov 13, 2024
1 parent af66797 commit b95b745
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,21 @@ impl DebugInfo {
/// This method returns a human-readable plain text debug report which can help
/// to identify issues.
pub async fn assemble(devices: Devices) -> DebugInfo {
let connectivity = gio::NetworkMonitor::default().connectivity();
let ping_results = std::iter::once(Device::new(
"localhost".to_owned(),
MacAddr6::nil(),
"localhost".to_owned(),
))
.chain(devices.into_iter())
.map(ping_device)
.collect::<FuturesOrdered<_>>()
.collect::<Vec<_>>()
let monitor = gio::NetworkMonitor::default();
let (connectivity, ping_results) = futures_util::future::join(
// Give network monitor time to actually figure out what the state of the network is,
// especially inside a flatpak sandbox, see https://gitlab.gnome.org/GNOME/glib/-/issues/1718
glib::timeout_future(Duration::from_millis(500)).map(|_| monitor.connectivity()),
std::iter::once(Device::new(
"localhost".to_owned(),
MacAddr6::nil(),
"localhost".to_owned(),
))
.chain(devices.into_iter())
.map(ping_device)
.collect::<FuturesOrdered<_>>()
.collect::<Vec<_>>(),
)
.await;
DebugInfo {
app_id: config::APP_ID,
Expand Down

0 comments on commit b95b745

Please sign in to comment.