Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rude-adults-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": minor
---

Fixes an issue where tokens generated while using the legacy notification provider would never be removed from the database.
13 changes: 10 additions & 3 deletions apps/meteor/app/push/server/fcm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,21 @@ type FCMError = {
};
};

// The 403 error code is used when the server is refusing to process a request to a specific token due to
// a SENDER_ID_MISMATCH error. This error is returned when the sender ID provided in the request does not match the sender ID
// associated with the registration token.
const SENDER_ID_MISMATCH_ERROR_CODE = 403;

/**
* Send a push notification using Firebase Cloud Messaging (FCM).
* implements the Firebase Cloud Messaging HTTP v1 API, and all of its retry logic,
* see: https://firebase.google.com/docs/reference/fcm/rest/v1/ErrorCode
*
* Errors:
* - For 400, 401, 403 errors: abort, and do not retry.
* - For 400, 401 errors: abort, and do not retry.
* - For 404 errors: remove the token from the database.
* - For 429 errors: retry after waiting for the duration set in the retry-after header. If no retry-after header is set, default to 60 seconds.
* - For 500 errors: retry with exponential backoff.
* - For 5xx errors: retry with exponential backoff.
*/
async function fetchWithRetry(url: string, _removeToken: () => void, options: ExtendedFetchOptions, retries = 0): Promise<Response> {
const MAX_RETRIES = 5;
Expand All @@ -81,7 +86,9 @@ async function fetchWithRetry(url: string, _removeToken: () => void, options: Ex
const retryAfter = response.headers.get('retry-after');
const retryAfterSeconds = retryAfter ? parseInt(retryAfter, 10) : 60;

if (response.status === 404) {
// This could happen if the sender ID has been changed (which happens when we change from legacy to new FCM).
// The same approach is used here: https://github.com/thingsboard/thingsboard/pull/10679
Comment thread
Gustrb marked this conversation as resolved.
Outdated
if (response.status === 404 || response.status === SENDER_ID_MISMATCH_ERROR_CODE) {
Comment thread
Gustrb marked this conversation as resolved.
Outdated
_removeToken();
return response;
}
Expand Down