Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat: enhance email cron reporting and error handling #1869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
feat: enhance email cron reporting and error handling #1869
Changes from all commits
2dfd7c3File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
Confirm the retention policy for recipient addresses in error logs.
Line 109 writes the recipient address into the error log on every dispatch exception. Static analysis flagged this as CWE-532. The cron report already sends addresses to Slack, so the address is not secret in this system. The concern is log retention, because application logs usually have a longer retention period than Slack messages.
If your retention policy limits personal data in application logs, remove the address from the log line. The
failureReasonrow at Line 111 already carries the address to the operator-facing report.🧰 Tools
🪛 ast-grep (0.45.1)
[warning] 108-108: Avoid logging sensitive data
Context: this.logger.error(
Failed to send reminder to ${email}: ${getErrorMessage(error)})Note: [CWE-532] Insertion of Sensitive Information into Log File.
(log-sensitive-data-typescript)
🤖 Prompt for AI Agents
Source: Linters/SAST tools
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win
Restore parallel dispatch. The queue concurrency is now ineffective.
The loop awaits each
queue.add(...)call before it enqueues the next address. Only one task is ever in the queue, so theconcurrency: 3setting has no effect and dispatch is serial.The gateway timeout is 4000 ms and the cron sends batches of 10 addresses. Serial dispatch raises the worst case per batch from about 4 s to about 40 s.
send2faEnabledInCompanyat Lines 120-139 keeps the previousPromise.allpattern for comparison.Enqueue every address first, then await the results together. Keep the try/catch inside the queued task so one failure does not discard the other results.
⚡ Proposed fix to restore concurrency
public async sendRemindersToUsers(userEmails: Array<string>): Promise<Array<ICronMessagingResults>> { const queue = new PQueue({ concurrency: 3 }); - const mailingResults: Array<ICronMessagingResults> = []; - - for (const email of userEmails) { - try { - const outcome = await queue.add(async () => { - return await this.dispatchEmailWithOutcome('reminder', email, {}); - }); - mailingResults.push( - mapReminderOutcomeToCronResult(email, outcome ?? { ok: false, reason: 'dispatch returned no outcome' }), - ); - } catch (error) { - this.logger.error(`Failed to send reminder to ${email}: ${getErrorMessage(error)}`); - Sentry.captureException(error); - mailingResults.push({ email, failureReason: `dispatch threw: ${getErrorMessage(error)}` }); - } - } - - await queue.onIdle(); + const mailingResults: Array<ICronMessagingResults> = await Promise.all( + userEmails.map((email) => + queue.add(async () => { + try { + const outcome = await this.dispatchEmailWithOutcome('reminder', email, {}); + return mapReminderOutcomeToCronResult(email, outcome); + } catch (error) { + this.logger.error(`Failed to send reminder: ${getErrorMessage(error)}`); + Sentry.captureException(error); + return { email, failureReason: `dispatch threw: ${getErrorMessage(error)}` }; + } + }).then( + (result) => result ?? { email, failureReason: 'dispatch returned no outcome' }, + ), + ), + ); return mailingResults; }Promise.allpreserves input order, so each result stays aligned with its address.📝 Committable suggestion
🧰 Tools
🪛 ast-grep (0.45.1)
[warning] 108-108: Avoid logging sensitive data
Context: this.logger.error(
Failed to send reminder to ${email}: ${getErrorMessage(error)})Note: [CWE-532] Insertion of Sensitive Information into Log File.
(log-sensitive-data-typescript)
🤖 Prompt for AI Agents
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.