mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-19 05:55:34 +09:00
fix(gateway): reject unknown rpc methods instead of crashing (#2238)
This commit is contained in:
1 parent
0e73346c5f
commit
2dd35c0d6e
4 files changed
+29
-3
No files matched your search
@@ -281,6 +281,8 @@ export class GatewayService {
|
|||||||
private readonly MAX_BATCH_CONCURRENCY = 50;
|
private readonly MAX_BATCH_CONCURRENCY = 50;
|
||||||
private readonly PENDING_REQUEST_TIMEOUT_MS = ms('30 seconds');
|
private readonly PENDING_REQUEST_TIMEOUT_MS = ms('30 seconds');
|
||||||
private readonly AUTH_CONTEXT_FALLBACK_MS = ms('5 minutes');
|
private readonly AUTH_CONTEXT_FALLBACK_MS = ms('5 minutes');
|
||||||
|
private readonly BADGE_COUNTS_FALLBACK_MS = ms('5 minutes');
|
||||||
|
private badgeCountsUnsupportedUntil = 0;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.rpcClient = GatewayRpcClient.getInstance();
|
this.rpcClient = GatewayRpcClient.getInstance();
|
||||||
@@ -703,15 +705,33 @@ export class GatewayService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async invalidatePushBadgeCounts({userIds}: InvalidatePushBadgeCountsParams): Promise<void> {
|
async invalidatePushBadgeCounts({userIds}: InvalidatePushBadgeCountsParams): Promise<void> {
|
||||||
|
if (Date.now() < this.badgeCountsUnsupportedUntil) {
|
||||||
|
await this.invalidatePushBadgeCountsIndividually(userIds);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const batches: Array<Array<UserID>> = [];
|
const batches: Array<Array<UserID>> = [];
|
||||||
for (let index = 0; index < userIds.length; index += PUSH_BADGE_COUNT_BATCH_SIZE) {
|
for (let index = 0; index < userIds.length; index += PUSH_BADGE_COUNT_BATCH_SIZE) {
|
||||||
batches.push(userIds.slice(index, index + PUSH_BADGE_COUNT_BATCH_SIZE));
|
batches.push(userIds.slice(index, index + PUSH_BADGE_COUNT_BATCH_SIZE));
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
batches.map((batch) =>
|
batches.map((batch) =>
|
||||||
this.call('push.invalidate_badge_counts', {user_ids: batch.map((userId) => userId.toString())}),
|
this.call('push.invalidate_badge_counts', {user_ids: batch.map((userId) => userId.toString())}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
} catch (error) {
|
||||||
|
const transformedError = this.transformGatewayError(error);
|
||||||
|
if (!this.isAuthContextUnsupportedError(transformedError)) {
|
||||||
|
throw transformedError;
|
||||||
|
}
|
||||||
|
this.badgeCountsUnsupportedUntil = Date.now() + this.BADGE_COUNTS_FALLBACK_MS;
|
||||||
|
Logger.warn({error}, '[gateway-rpc] push.invalidate_badge_counts unavailable, falling back to per-user calls');
|
||||||
|
await this.invalidatePushBadgeCountsIndividually(userIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async invalidatePushBadgeCountsIndividually(userIds: ReadonlyArray<UserID>): Promise<void> {
|
||||||
|
await Promise.all(userIds.map((userId) => this.invalidatePushBadgeCount({userId})));
|
||||||
}
|
}
|
||||||
|
|
||||||
async invalidatePushSubscriptions({userId}: InvalidatePushSubscriptionsParams): Promise<void> {
|
async invalidatePushSubscriptions({userId}: InvalidatePushSubscriptionsParams): Promise<void> {
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ execute_method(<<"process.voice_state_counts">>, _Params) ->
|
|||||||
gateway_rpc_misc_presence:collect_and_aggregate_voice_state_counts(ActiveNodes);
|
gateway_rpc_misc_presence:collect_and_aggregate_voice_state_counts(ActiveNodes);
|
||||||
execute_method(<<"process.active_voice_rooms">>, _Params) ->
|
execute_method(<<"process.active_voice_rooms">>, _Params) ->
|
||||||
ActiveNodes = gateway_node_router:active_nodes(),
|
ActiveNodes = gateway_node_router:active_nodes(),
|
||||||
gateway_rpc_misc_push:collect_and_aggregate_active_voice_rooms(ActiveNodes).
|
gateway_rpc_misc_push:collect_and_aggregate_active_voice_rooms(ActiveNodes);
|
||||||
|
execute_method(Method, _Params) ->
|
||||||
|
gateway_rpc_error:raise(<<"Unknown method: ", Method/binary>>).
|
||||||
|
|
||||||
-spec get_local_node_id() -> binary().
|
-spec get_local_node_id() -> binary().
|
||||||
get_local_node_id() ->
|
get_local_node_id() ->
|
||||||
|
|||||||
@@ -20,7 +20,9 @@ execute_method(<<"presence.terminate_all_sessions">>, P) -> handle_terminate_all
|
|||||||
execute_method(<<"presence.has_active">>, P) -> handle_has_active(P);
|
execute_method(<<"presence.has_active">>, P) -> handle_has_active(P);
|
||||||
execute_method(<<"presence.add_temporary_guild">>, P) -> handle_add_temp_guild(P);
|
execute_method(<<"presence.add_temporary_guild">>, P) -> handle_add_temp_guild(P);
|
||||||
execute_method(<<"presence.remove_temporary_guild">>, P) -> handle_remove_temp_guild(P);
|
execute_method(<<"presence.remove_temporary_guild">>, P) -> handle_remove_temp_guild(P);
|
||||||
execute_method(<<"presence.sync_group_dm_recipients">>, P) -> handle_sync_dm_recipients(P).
|
execute_method(<<"presence.sync_group_dm_recipients">>, P) -> handle_sync_dm_recipients(P);
|
||||||
|
execute_method(Method, _Params) ->
|
||||||
|
gateway_rpc_error:raise(<<"Unknown method: ", Method/binary>>).
|
||||||
|
|
||||||
-spec handle_dispatch(map()) -> true.
|
-spec handle_dispatch(map()) -> true.
|
||||||
handle_dispatch(#{<<"user_id">> := UserIdBin, <<"event">> := Event, <<"data">> := Data}) ->
|
handle_dispatch(#{<<"user_id">> := UserIdBin, <<"event">> := Event, <<"data">> := Data}) ->
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ execute_method(<<"push.invalidate_badge_counts">>, P) ->
|
|||||||
execute_method(<<"push.clear_channel_notifications">>, P) ->
|
execute_method(<<"push.clear_channel_notifications">>, P) ->
|
||||||
do_clear_channel_notifications(P);
|
do_clear_channel_notifications(P);
|
||||||
execute_method(<<"push.invalidate_subscriptions">>, P) ->
|
execute_method(<<"push.invalidate_subscriptions">>, P) ->
|
||||||
do_invalidate_subscriptions(P).
|
do_invalidate_subscriptions(P);
|
||||||
|
execute_method(Method, _Params) ->
|
||||||
|
gateway_rpc_error:raise(<<"Unknown method: ", Method/binary>>).
|
||||||
|
|
||||||
-spec do_sync_user_guild_settings(map()) -> true.
|
-spec do_sync_user_guild_settings(map()) -> true.
|
||||||
do_sync_user_guild_settings(#{
|
do_sync_user_guild_settings(#{
|
||||||
|
|||||||
Reference in new issue
Block a user