-
-
Notifications
You must be signed in to change notification settings - Fork 166
feat(realtime): subscribe retry improvements #747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 16438495062Details
💛 - Coveralls |
- Add missing return statement in subscribeWithError() to prevent infinite retries - Add heartbeat response handling in testBehavior test - Fix test expectations for retry attempts - Ensure proper cleanup on subscription failure This fixes the issue where successful subscriptions would continue retrying and tests would fail due to incorrect retry attempt counting.
4906875
to
d702903
Compare
logger?.error("Subscribe failed: \(error)") | ||
} | ||
} | ||
_ = await statusChange.first { @Sendable in $0 == .subscribed } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some consideration on what await subscribe()
should wait for exactly. @filipecabaco explained that both the broadcast and the presence parts should be considered as subscribed
on the message acknoledgement success, which is what is currently being done:
supabase-swift/Sources/Realtime/RealtimeChannelV2.swift
Lines 281 to 289 in 8ac8c4a
case .system: | |
if message.status == .ok { | |
logger?.debug("Subscribed to channel \(message.topic)") | |
status = .subscribed | |
} else { | |
logger?.debug( | |
"Failed to subscribe to channel \(message.topic): \(message.payload)" | |
) | |
} |
but the postgres_changes
part is only available when it receives the system message saying you're subscribed, which may take some time. This is already the current behavior, but maybe it is worth it adding this distinction in the RealtimeSubscribedStates
, as a client may only be subscribed to broadcast
, or presence
or postgres_changes
at any given time.
What kind of change does this PR introduce?
#742
What is the current behavior?
Channel doesn't have a limit for retrying, so it keeps retrying indefinitely, which causes a crash due the recursive call.
What is the new behavior?
Add a max retry attempt configuration (default to 5 attempts), along with a backoff + jitter delay calculation for the retry.
subscribeWithError()
which throws aRealtimeError.maxRetryAttemptsReached
or aCancellationError
.subscribe()
method in favor of thesubscribeWithError()
subscribeWithError()
back tosubscribe()
and remove thewithError
variant, it means the default will be the throwing method.Additional context
Add any other context or screenshots.