Fixed ghost channel subscription

This commit is contained in:
2026-03-01 20:31:13 +08:00
parent 029e671367
commit 3950f3ee94
3 changed files with 19 additions and 5 deletions
+11 -1
View File
@@ -329,12 +329,22 @@ class StreamRecoveryWrapper<T> {
_startRealtimeSubscription();
}
/// Clean up all resources.
/// Clean up all resources and notify the status callback that this
/// channel is no longer active, preventing ghost entries in the
/// [RealtimeController]'s recovering-channels set.
void dispose() {
if (_disposed) return;
_disposed = true;
_pollingTimer?.cancel();
_recoveryTimer?.cancel();
_realtimeSub?.cancel();
// Ensure the channel is removed from the recovering set when the
// wrapper is torn down (e.g. provider disposed during navigation).
// Without this, disposed wrappers that were mid-recovery leave
// orphaned entries that keep the reconnection indicator spinning.
if (_connectionStatus != StreamConnectionStatus.connected) {
_onStatusChanged?.call(channelName, StreamConnectionStatus.connected);
}
_controller?.close();
}
}