Skip to content

Commit

Permalink
fix(datastore): reconnect the AppSyncRealTimeClient once connection i…
Browse files Browse the repository at this point in the history
…s stale (#3734)
  • Loading branch information
5d authored Jun 4, 2024
1 parent 2a233c4 commit ad53816
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,16 @@ actor AppSyncRealTimeClient: AppSyncRealTimeClientProtocol {
.eraseToAnyPublisher()
}

private func reconnect() async {
do {
log.debug("[AppSyncRealTimeClient] Reconnecting")
await disconnect()
try await connect()
} catch {
log.debug("[AppSyncRealTimeClient] Failed to reconnect, error: \(error)")
}
}

private static func decodeAppSyncRealTimeResponseError(_ data: JSONValue?) -> [Error] {
let knownAppSyncRealTimeRequestErorrs =
Self.decodeAppSyncRealTimeRequestError(data)
Expand Down Expand Up @@ -414,7 +424,7 @@ extension AppSyncRealTimeClient {
.sink(receiveValue: {
self.log.debug("[AppSyncRealTimeClient] KeepAlive timed out, disconnecting")
Task { [weak self] in
await self?.disconnect()
await self?.reconnect()
}.toAnyCancellable.store(in: &self.cancellables)
})
.store(in: &cancellablesBindToConnection)
Expand Down

0 comments on commit ad53816

Please sign in to comment.