Skip to content

Commit d42df03

Browse files
committed
fix: fixed error code check (closes #423), improved speed of frozen queue check job with cursor
1 parent f33cbc7 commit d42df03

File tree

2 files changed

+49
-28
lines changed

2 files changed

+49
-28
lines changed

helpers/get-error-code.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,24 @@ function getErrorCode(err) {
3636
// hard-coded denylist errors have 550 while others have 421
3737
if (err.name === 'DenylistError') return err.responseCode;
3838
if (
39-
(typeof err.responseCode !== 'number' || err.responseCode > 500) &&
39+
err.bounceInfo.category === 'block' &&
40+
err.responseCode >= 500 &&
41+
err.bounceInfo.action === 'reject' &&
42+
[
43+
'Using dynamic IP range',
44+
'Sender is open relay',
45+
'Sender IP blocked'
46+
].includes(err.bounceInfo.message)
47+
) {
48+
return 421;
49+
}
50+
51+
if (
52+
(typeof err.responseCode !== 'number' || err.responseCode >= 500) &&
53+
err.bounceInfo.action !== 'reject' &&
54+
err.bounceInfo.category !== 'protocol' &&
4055
(['defer', 'slowdown'].includes(err.bounceInfo.action) ||
41-
['block', 'blocklist', 'network', 'protocol', 'policy'].includes(
56+
['blocklist', 'network', 'protocol', 'policy'].includes(
4257
err.bounceInfo.category
4358
))
4459
)

jobs/check-smtp-frozen-queue.js

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,41 @@ graceful.listen();
4545
// get list of all suspended domains
4646
// and recently blocked emails to exclude
4747
const now = new Date();
48-
let [suspendedDomainIds, recentlyBlockedIds] = await Promise.all([
49-
Domains.aggregate([
50-
{ $match: { is_smtp_suspended: true } },
51-
{ $group: { _id: '$_id' } }
52-
])
53-
.allowDiskUse(true)
54-
.exec(),
55-
Emails.aggregate([
56-
{
57-
$match: {
58-
updated_at: {
59-
$gte: dayjs().subtract(1, 'hour').toDate(),
60-
$lte: now
61-
},
62-
has_blocked_hashes: true,
63-
blocked_hashes: {
64-
$in: getBlockedHashes(env.SMTP_HOST)
65-
}
48+
const suspendedDomainIds = [];
49+
const recentlyBlockedIds = [];
50+
51+
await Promise.all([
52+
(async () => {
53+
for await (const domain of Domains.find({
54+
is_smtp_suspended: true
55+
})
56+
.select('_id')
57+
.lean()
58+
.cursor()
59+
.addCursorFlag('noCursorTimeout', true)) {
60+
suspendedDomainIds.push(domain._id);
61+
}
62+
})(),
63+
(async () => {
64+
for await (const email of Emails.find({
65+
updated_at: {
66+
$gte: dayjs().subtract(1, 'hour').toDate(),
67+
$lte: now
68+
},
69+
has_blocked_hashes: true,
70+
blocked_hashes: {
71+
$in: getBlockedHashes(env.SMTP_HOST)
6672
}
67-
},
68-
{ $group: { _id: '$_id' } }
69-
])
70-
.allowDiskUse(true)
71-
.exec()
73+
})
74+
.select('_id')
75+
.lean()
76+
.cursor()
77+
.addCursorFlag('noCursorTimeout', true)) {
78+
recentlyBlockedIds.push(email._id);
79+
}
80+
})()
7281
]);
7382

74-
suspendedDomainIds = suspendedDomainIds.map((v) => v._id);
75-
recentlyBlockedIds = recentlyBlockedIds.map((v) => v._id);
76-
7783
logger.info('%d suspended domain ids', suspendedDomainIds.length);
7884

7985
logger.info('%d recently blocked ids', recentlyBlockedIds.length);

0 commit comments

Comments
 (0)