Skip to content

Stop treating an unknown network state as offline - #78

Merged
aleksandar-apostolov merged 1 commit into
developfrom
fix/and-1486-unknown-network-not-offline
Sep 9, 2026
Merged

aleksandar-apostolov merged 1 commit into
developfrom
fix/and-1486-unknown-network-not-offline

Conversation

@aleksandar-apostolov

Copy link
Copy Markdown
Collaborator

Goal

Fixes AND-1486

StreamConnectionRecoveryEvaluatorImpl read every non-Available network state as offline,
StreamNetworkState.Unknown included. Unknown is the state before any connectivity callback has
fired: StreamNetworkMonitorCallback.onRegistered() seeds a state only when the platform reports a
viable network, so on a device with none it stays Unknown.

A foreground signal arriving in that state while the socket was still Connecting satisfied
shouldDisconnect, so recoveryEffect cancelled the connect single-flight and disconnected the
socket — the caller's connect() ended in cancellation instead of the socket or network error it
should have surfaced. Reachable once #77 lands: before it, the blocking attach in
StreamLifecycleMonitorImpl.start() completed ahead of the listener subscription, so the replayed
ON_RESUME reached nobody.

Implementation

Only a reported loss counts as offline now, Disconnected or Unavailable. Unknown no longer
contributes to shouldDisconnect, which matches the lifecycle side of the same expression: it
already tests == Background rather than != Foreground, so an Unknown lifecycle state has
never been read as backgrounded.

shouldConnect is untouched. It keys off Available, so Unknown never triggered a reconnect and
still doesn't.

Testing

:stream-android-core:testDebugUnitTest with --rerun-tasks.

Two new tests. One asserts no recovery for a Connecting socket with an Unknown network state;
reverting the guard reddens it and nothing else. One pins the Unavailable arm of the new check,
which had no coverage — every existing disconnect test uses Disconnected.

One pre-existing failure in the run: StreamCompositeEventSerializationImplTest.serialize - neither core nor product returns failure picks a constructor with declaredConstructors.first() and calls
it with three arguments. It passes in isolation, fails in a full run, and develop fails the same
way in a clean worktree.

Detekt: 1309 weighted issues, matching the develop baseline.

Checklist

  • Issue linked (if any)
  • Tests/docs updated
  • I have signed the Stream CLA (required for external contributors)

`shouldDisconnect` read every non-Available network state as offline, `Unknown`
included -- the state before any connectivity callback has fired. When the
platform reports no viable network at registration time the monitor never seeds
a state, so a foreground signal arriving while the socket is still connecting
evaluates to Recovery.Disconnect and cancels the caller's connect() rather than
letting it fail on its own.

Only a reported loss counts as offline now, `Disconnected` or `Unavailable`,
which matches how an `Unknown` lifecycle state is already handled.
@aleksandar-apostolov aleksandar-apostolov added the pr:bug Bug fix label Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled, or the PR is bot-authored.
  • An issue is linked (Linear ticket or GitHub issue), or the PR is bot-authored.

🎉 Great job! This PR is ready for review.

@aleksandar-apostolov
aleksandar-apostolov marked this pull request as ready for review September 3, 2026 14:25
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 1a7c786c-b768-44b1-8606-cd11d65f38c0


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

@aleksandar-apostolov
aleksandar-apostolov merged commit e80f8a4 into develop Sep 9, 2026
13 of 15 checks passed
@aleksandar-apostolov
aleksandar-apostolov deleted the fix/and-1486-unknown-network-not-offline branch September 9, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants