Skip to content

Commit a3522a4

Browse files
authored
Adjust group refresh timeout behavior
1 parent e0b1771 commit a3522a4

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

SignalServiceKit/Groups/GroupV2UpdatesImpl.swift

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,12 @@ private extension GroupV2UpdatesImpl {
335335

336336
do {
337337
// Try to use individual changes.
338-
try await Promise.wrapAsync {
339-
try await self.fetchAndApplyChangeActionsFromService(
340-
secretParams: secretParams,
341-
spamReportingMetadata: spamReportingMetadata,
342-
source: source,
343-
options: options
344-
)
345-
}.timeout(seconds: GroupManager.groupUpdateTimeoutDuration, description: "Update via changes") {
346-
return GroupsV2Error.timeout
347-
}.awaitable()
338+
try await self.fetchAndApplyChangeActionsFromService(
339+
secretParams: secretParams,
340+
spamReportingMetadata: spamReportingMetadata,
341+
source: source,
342+
options: options
343+
)
348344
} catch {
349345
let shouldTrySnapshot = { () -> Bool in
350346
// This should not fail over in the case of networking problems.
@@ -379,15 +375,11 @@ private extension GroupV2UpdatesImpl {
379375
}
380376

381377
// Failover to applying latest snapshot.
382-
try await Promise.wrapAsync {
383-
try await self.fetchAndApplyCurrentGroupV2SnapshotFromService(
384-
secretParams: secretParams,
385-
spamReportingMetadata: spamReportingMetadata,
386-
options: options
387-
)
388-
}.timeout(seconds: GroupManager.groupUpdateTimeoutDuration, description: "Update via snapshot") {
389-
return GroupsV2Error.timeout
390-
}.awaitable()
378+
try await self.fetchAndApplyCurrentGroupV2SnapshotFromService(
379+
secretParams: secretParams,
380+
spamReportingMetadata: spamReportingMetadata,
381+
options: options
382+
)
391383
}
392384
}
393385

SignalServiceKit/Groups/GroupsV2Impl.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ public class GroupsV2Impl: GroupsV2 {
4949
observeNotifications()
5050
}
5151

52+
private func refreshGroupWithTimeout(secretParams: GroupSecretParams) async throws {
53+
do {
54+
// Ignore the result after the timeout. However, keep refreshing the group
55+
// in the background since the result is still useful/reusable.
56+
try await withUncooperativeTimeout(seconds: GroupManager.groupUpdateTimeoutDuration) {
57+
try await SSKEnvironment.shared.groupV2UpdatesRef.refreshGroup(secretParams: secretParams)
58+
}
59+
} catch is UncooperativeTimeoutError {
60+
throw GroupsV2Error.timeout
61+
}
62+
}
63+
5264
// MARK: - Notifications
5365

5466
private func observeNotifications() {
@@ -223,7 +235,7 @@ public class GroupsV2Impl: GroupsV2 {
223235
// committed to the service, we should refresh our local state
224236
// for the group and try again to apply our changes.
225237

226-
try await SSKEnvironment.shared.groupV2UpdatesRef.refreshGroup(secretParams: groupV2Params.groupSecretParams)
238+
try await refreshGroupWithTimeout(secretParams: groupV2Params.groupSecretParams)
227239

228240
(messageBehavior, httpResponse) = try await buildGroupChangeProtoAndTryToUpdateGroupOnService(
229241
groupId: groupId,
@@ -1587,7 +1599,7 @@ public class GroupsV2Impl: GroupsV2 {
15871599
// First try to fetch latest group state from service.
15881600
// This will fail for users trying to join via group link
15891601
// who are not yet in the group.
1590-
try await SSKEnvironment.shared.groupV2UpdatesRef.refreshGroup(secretParams: secretParams)
1602+
try await refreshGroupWithTimeout(secretParams: secretParams)
15911603

15921604
let groupThread = SSKEnvironment.shared.databaseStorageRef.read { tx in
15931605
return TSGroupThread.fetch(forGroupId: groupId, tx: tx)

0 commit comments

Comments
 (0)