Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

peer_data: Clear the pending request entry after giving up.

Shubham Padia40c384fe251c
diff --git a/web/src/peer_data.ts b/web/src/peer_data.ts
index fe0a740ae99..7a1d3a64e66 100644
--- a/web/src/peer_data.ts
+++ b/web/src/peer_data.ts
@@ -597,6 +597,7 @@ export async function fetch_subscriptions_for_user(user_id: number): Promise<voi
}
}
if (num_attempts === 5) {
+ pending_subscription_requests.delete(user_id);
blueslip.error("Failure fetching user's subscribed channels. Giving up.", {
user_id,
});
diff --git a/web/tests/peer_data.test.cjs b/web/tests/peer_data.test.cjs
index e4d10ef31c4..a077dd65ef1 100644
--- a/web/tests/peer_data.test.cjs
+++ b/web/tests/peer_data.test.cjs
@@ -663,6 +663,19 @@ test("fetch_subscriptions_for_user", async () => {
await peer_data.fetch_subscriptions_for_user(fred.user_id);
blueslip.reset();
+ // After giving up, a later call should start a new fetch instead
+ // of returning the finished request's promise.
+ channel_get_calls = 0;
+ mock_channel_get(channel, (opts) => {
+ channel_get_calls += 1;
+ opts.success({
+ subscribed_channel_ids: [india.stream_id],
+ });
+ });
+ await peer_data.fetch_subscriptions_for_user(fred.user_id);
+ assert.equal(channel_get_calls, 1);
+ assert.ok(stream_data.is_user_loaded_and_subscribed(india.stream_id, fred.user_id));
+
peer_data.clear_for_testing();
mock_channel_get(channel, (opts) => {
opts.error({status: 400, responseJSON: {msg: "bad request"}});