{"record":{"id":"6c118e16198f418d","repo":"RocketChat/Rocket.Chat","slug":"failed-to-set-user-avatar-from-pending-url","errorCode":null,"errorMessage":"Failed to set user avatar from pending URL","messagePattern":"Failed to set user avatar from pending URL","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"apps/meteor/server/lib/import/pending-avatars/PendingAvatarImporter.ts","lineNumber":52,"sourceCode":"\t}\n\n\toverride async startImport(importSelection: IImporterShortSelection): Promise<ImporterProgress> {\n\t\tconst pendingFileUserList = Users.findAllUsersWithPendingAvatar();\n\t\ttry {\n\t\t\tfor await (const user of pendingFileUserList) {\n\t\t\t\ttry {\n\t\t\t\t\tconst { _pendingAvatarUrl: url, name, _id } = user;\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tif (!url?.startsWith('http')) {\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait setAvatarFromServiceWithValidation(_id, url, undefined, 'url');\n\t\t\t\t\t\t\tawait Users.updateOne({ _id }, { $unset: { _pendingAvatarUrl: '' } });\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tthis.logger.warn({ msg: 'Failed to set user avatar from pending URL', name, url });\n\t\t\t\t\t\t}\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tawait this.addCountCompleted(1);\n\t\t\t\t\t}\n\t\t\t\t} catch (error) {\n\t\t\t\t\tthis.logger.error({ msg: 'Failed to process pending avatar for user', err: error });\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// If the cursor expired, restart the method\n\t\t\tif (this.isCursorNotFoundError(error)) {\n\t\t\t\tthis.logger.info('CursorNotFound');\n\t\t\t\treturn this.startImport(importSelection);\n\t\t\t}\n\n\t\t\tawait super.updateProgress(ProgressStep.ERROR);\n\t\t\tthrow error;\n\t\t}","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/import/pending-avatars/PendingAvatarImporter.ts#L34-L70","documentation":"The pending-avatars import step sets each user's avatar from the _pendingAvatarUrl stored during import using setAvatarFromServiceWithValidation; the call failed for this user and is logged per-user (the step continues and the completed counter still advances). The _pendingAvatarUrl field is left in place, so the user keeps a pending URL that can be retried.","triggerScenarios":"Avatar URL returning 404/403 (expired signed Slack/S3 links, private buckets); response content-type not an image or unsupported format; image exceeding the avatar size/validation limits; server-side fetch blocked by egress rules; user record deleted meanwhile.","commonSituations":"Running the avatar step long after the export so signed URLs expired; servers without outbound internet; avatars hosted on intranet hosts unreachable from Rocket.Chat; oversized images failing validation.","solutions":["From the server host, curl the logged url to see the exact status code (404/403/timeout)","For expired or private URLs, re-export or rehost avatars at stable public URLs, then re-run the pending-avatars step","Fix egress rules if the server cannot reach the avatar hosts","Accept the fallback (initials avatar) by unsetting _pendingAvatarUrl for the affected users"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// only queue URLs the server can actually fetch\nif (!/^https?:\\/\\//.test(url)) continue; // already checked: only http(s) allowed\nconst head = await fetch(url, { method: 'HEAD' }).catch(() => undefined);\nif (!head?.ok) {\n\tthis.logger.warn({ msg: 'Skipping unreachable pending avatar', name, url, status: head?.status });\n\tcontinue;\n}","typeGuard":null,"tryCatchPattern":"try {\n\tawait setAvatarFromServiceWithValidation(_id, url, undefined, 'url');\n\tawait Users.updateOne({ _id }, { $unset: { _pendingAvatarUrl: '' } });\n} catch (error) {\n\tthis.logger.warn({ msg: 'Failed to set user avatar from pending URL', name, url });\n\t// _pendingAvatarUrl stays set so a later run can retry\n} finally {\n\tawait this.addCountCompleted(1);\n}","preventionTips":["Run the avatar import step soon after export so signed avatar URLs are still valid","Ensure the server can reach external avatar hosts (egress rules, proxies)","Track per-user failures so retriable URLs are re-run instead of silently counted"],"tags":["import","avatars","url-fetch","users","importer"],"backgroundTag":"avatar-url-fetch-failed","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}