@bobfrankston/rmfmail 1.2.47 → 1.2.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/packages/mailx-imap/index.d.ts +44 -44
- package/packages/mailx-imap/index.d.ts.map +1 -1
- package/packages/mailx-imap/index.js +141 -132
- package/packages/mailx-imap/index.js.map +1 -1
- package/packages/mailx-imap/index.ts +140 -135
- package/packages/mailx-imap/package-lock.json +2 -2
- package/packages/mailx-imap/package.json +1 -1
|
@@ -24,15 +24,13 @@ const SMTP_PORT_STARTTLS = 587;
|
|
|
24
24
|
const SMTP_PORT_IMPLICIT_TLS = 465;
|
|
25
25
|
|
|
26
26
|
type OpsTask = () => Promise<void>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
runningFast: boolean;
|
|
35
|
-
runningSlow: boolean;
|
|
27
|
+
/** One FIFO task queue per (account, lane). All lanes drain concurrently —
|
|
28
|
+
* each lane runs on its own persistent connection — so a slow op on one lane
|
|
29
|
+
* never blocks another. Within a lane, strictly sequential (one IMAP command
|
|
30
|
+
* in flight, no SELECT races). */
|
|
31
|
+
interface LaneQueue {
|
|
32
|
+
tasks: OpsTask[];
|
|
33
|
+
running: boolean;
|
|
36
34
|
}
|
|
37
35
|
interface HostSemaphore {
|
|
38
36
|
permits: number;
|
|
@@ -591,39 +589,45 @@ export class ImapManager extends EventEmitter {
|
|
|
591
589
|
// No semaphore, no pool, no per-operation connect/disconnect.
|
|
592
590
|
// IDLE uses a separate connection (see startWatching).
|
|
593
591
|
|
|
594
|
-
/**
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
*
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
*
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
592
|
+
/** Per-workload connection lanes. Each (lane, account) gets its OWN
|
|
593
|
+
* persistent IMAP connection so a slow op on one lane can't block another:
|
|
594
|
+
* a 90s `SELECT Sent` on "outbox" or a giant `UID FETCH` on "prefetch" no
|
|
595
|
+
* longer wedges INBOX sync/backfill on "sync". This is the root fix for
|
|
596
|
+
* the "whole sync worker goes silent" wedge (Bob 2026-06-20): before, all
|
|
597
|
+
* background work shared ONE slow connection and serialized behind the
|
|
598
|
+
* slowest command (a 90s SELECT Sent / a giant prefetch FETCH stalled
|
|
599
|
+
* INBOX backfill behind it). Lanes in use:
|
|
600
|
+
* fast — interactive: body fetch on click, flag toggle, move
|
|
601
|
+
* slow — folder sync + set-diff backfill (the `{slow:true}` default)
|
|
602
|
+
* prefetch — background body download (heaviest, longest)
|
|
603
|
+
* outbox — send + sent-sweep + Outbox/Sent SELECT/APPEND
|
|
604
|
+
* Per account that's ≤4 persistent sockets + 1 IDLE, under Dovecot's 20.
|
|
605
|
+
* laneName → (accountId → persistent client). */
|
|
606
|
+
private laneClients = new Map<string, Map<string, any>>();
|
|
607
|
+
/** Per-account, per-lane FIFO task queues. accountId → (laneName → queue).
|
|
608
|
+
* All lanes for an account drain concurrently (each on its own socket);
|
|
609
|
+
* within a lane, strictly sequential — no SELECT race. */
|
|
610
|
+
private laneQueues = new Map<string, Map<string, LaneQueue>>();
|
|
611
611
|
/** Per-host semaphore — caps simultaneous IMAP socket opens to one server.
|
|
612
|
-
* Defensive guardrail
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
*
|
|
612
|
+
* Defensive guardrail for the multi-account-on-one-host case (e.g. bobma +
|
|
613
|
+
* bobma2 both on imap.iecc.com). NOTE: the permit is held for the
|
|
614
|
+
* connection's LIFETIME (released on logout/destroy), not just the open —
|
|
615
|
+
* so this also bounds the number of live persistent connections per host.
|
|
616
|
+
* Each account now keeps up to 4 persistent lanes (fast/slow/prefetch/
|
|
617
|
+
* outbox) + 1 IDLE (IDLE bypasses the semaphore). 8 permits covers two
|
|
618
|
+
* accounts' lanes with headroom, still far under Dovecot's ~20/user+IP. */
|
|
616
619
|
private hostSemaphores = new Map<string, HostSemaphore>();
|
|
617
|
-
private static readonly HOST_PERMITS =
|
|
618
|
-
|
|
619
|
-
/**
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
620
|
+
private static readonly HOST_PERMITS = 8;
|
|
621
|
+
|
|
622
|
+
/** The (accountId → client) map for a lane, created on first use. */
|
|
623
|
+
private laneClientMap(lane: string): Map<string, any> {
|
|
624
|
+
let m = this.laneClients.get(lane);
|
|
625
|
+
if (!m) { m = new Map(); this.laneClients.set(lane, m); }
|
|
626
|
+
return m;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
private async getLaneClient(accountId: string, lane: string): Promise<any> {
|
|
630
|
+
const map = this.laneClientMap(lane);
|
|
627
631
|
let client = map.get(accountId);
|
|
628
632
|
if (client) {
|
|
629
633
|
// C38: health-check the cached client before returning. If the
|
|
@@ -640,7 +644,7 @@ export class ImapManager extends EventEmitter {
|
|
|
640
644
|
console.log(` [conn] ${accountId}: stale ${lane} client detected — reconnecting`);
|
|
641
645
|
client = undefined as any;
|
|
642
646
|
}
|
|
643
|
-
client = await this.newClient(accountId, lane
|
|
647
|
+
client = await this.newClient(accountId, lane);
|
|
644
648
|
// Wrap logout as no-op — this is a persistent connection. The
|
|
645
649
|
// newClient wrapper's close-counter runs on `_realLogout`.
|
|
646
650
|
const realLogout = client.logout.bind(client);
|
|
@@ -657,33 +661,30 @@ export class ImapManager extends EventEmitter {
|
|
|
657
661
|
return this.getLaneClient(accountId, "slow");
|
|
658
662
|
}
|
|
659
663
|
|
|
660
|
-
/** Run an operation
|
|
661
|
-
|
|
662
|
-
*
|
|
663
|
-
*
|
|
664
|
-
* recovery" paths the old multi-client design needed.
|
|
664
|
+
/** Run an operation against one of the account's per-workload lane
|
|
665
|
+
* connections. Tasks queue strictly sequentially WITHIN a lane (one IMAP
|
|
666
|
+
* command in flight, no SELECT race) but lanes run CONCURRENTLY, each on
|
|
667
|
+
* its own socket — so a slow op on one lane never blocks another.
|
|
665
668
|
*
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
* When both lanes have tasks, fast drains first.
|
|
669
|
+
* Pick the lane via `opts.lane` (e.g. "sync", "prefetch", "outbox").
|
|
670
|
+
* Default is "fast" — interactive ops (body fetch on click, flag toggle,
|
|
671
|
+
* move). `slow: true` is a legacy alias for the "slow" misc lane; prefer
|
|
672
|
+
* a named lane so distinct workloads don't serialize behind each other.
|
|
671
673
|
*
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
+
* The running task always finishes — IMAP can't preempt a command
|
|
675
|
+
* mid-flight; the wall-clock timeout below bounds how long that can be. */
|
|
674
676
|
async withConnection<T>(
|
|
675
677
|
accountId: string,
|
|
676
678
|
fn: (client: any) => Promise<T>,
|
|
677
|
-
opts: { slow?: boolean; timeoutMs?: number } = {},
|
|
679
|
+
opts: { slow?: boolean; lane?: string; timeoutMs?: number } = {},
|
|
678
680
|
): Promise<T> {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
}
|
|
684
|
-
const lane: "fast" | "slow" = opts.slow ? "slow" : "fast";
|
|
681
|
+
const lane: string = opts.lane ?? (opts.slow ? "slow" : "fast");
|
|
682
|
+
let perAccount = this.laneQueues.get(accountId);
|
|
683
|
+
if (!perAccount) { perAccount = new Map(); this.laneQueues.set(accountId, perAccount); }
|
|
684
|
+
let queue = perAccount.get(lane);
|
|
685
|
+
if (!queue) { queue = { tasks: [], running: false }; perAccount.set(lane, queue); }
|
|
685
686
|
// Per-task wall-clock cap. Without one, a wedged IMAP command (TCP
|
|
686
|
-
// half-open, server stalled mid-FETCH) keeps the
|
|
687
|
+
// half-open, server stalled mid-FETCH) keeps the lane's running flag
|
|
687
688
|
// set forever and every subsequent same-lane task — including the
|
|
688
689
|
// retry button the user just hit — waits behind it. Default is
|
|
689
690
|
// generous; callers driving user-visible reads pass a tighter value.
|
|
@@ -703,13 +704,12 @@ export class ImapManager extends EventEmitter {
|
|
|
703
704
|
resolve(result);
|
|
704
705
|
} catch (e: any) {
|
|
705
706
|
clearTimeout(timer);
|
|
706
|
-
// Discard
|
|
707
|
-
// socket poisons every subsequent request on
|
|
708
|
-
//
|
|
709
|
-
//
|
|
710
|
-
//
|
|
711
|
-
|
|
712
|
-
const map = lane === "fast" ? this.fastClients : this.opsClients;
|
|
707
|
+
// Discard THIS lane's client on any error — a half-broken
|
|
708
|
+
// socket poisons every subsequent request on the lane.
|
|
709
|
+
// Other lanes' clients are independent and untouched.
|
|
710
|
+
// Destroy synchronously kills the in-flight command's
|
|
711
|
+
// socket so the underlying promise rejects.
|
|
712
|
+
const map = this.laneClientMap(lane);
|
|
713
713
|
const stale = map.get(accountId);
|
|
714
714
|
map.delete(accountId);
|
|
715
715
|
if (stale) {
|
|
@@ -719,31 +719,27 @@ export class ImapManager extends EventEmitter {
|
|
|
719
719
|
reject(e);
|
|
720
720
|
}
|
|
721
721
|
};
|
|
722
|
-
queue
|
|
722
|
+
queue!.tasks.push(task);
|
|
723
723
|
this.drainOpsQueue(accountId);
|
|
724
724
|
});
|
|
725
725
|
}
|
|
726
726
|
|
|
727
|
-
/**
|
|
728
|
-
*
|
|
729
|
-
*
|
|
730
|
-
* same lane. */
|
|
727
|
+
/** Drain the next queued task on EVERY lane for the account. Lanes run
|
|
728
|
+
* concurrently — each on its own connection — and the per-lane running
|
|
729
|
+
* flag prevents reentrant draining of the same lane. */
|
|
731
730
|
private drainOpsQueue(accountId: string): void {
|
|
732
|
-
const
|
|
733
|
-
if (!
|
|
734
|
-
const
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
queue[runningKey] = true;
|
|
731
|
+
const perAccount = this.laneQueues.get(accountId);
|
|
732
|
+
if (!perAccount) return;
|
|
733
|
+
for (const queue of perAccount.values()) {
|
|
734
|
+
if (queue.running) continue;
|
|
735
|
+
const next = queue.tasks.shift();
|
|
736
|
+
if (!next) continue;
|
|
737
|
+
queue.running = true;
|
|
740
738
|
next().finally(() => {
|
|
741
|
-
queue
|
|
742
|
-
|
|
739
|
+
queue.running = false;
|
|
740
|
+
this.drainOpsQueue(accountId);
|
|
743
741
|
});
|
|
744
|
-
}
|
|
745
|
-
drainLane("fast");
|
|
746
|
-
drainLane("slow");
|
|
742
|
+
}
|
|
747
743
|
}
|
|
748
744
|
|
|
749
745
|
/** Acquire one slot of the per-host connection semaphore. Returns a release
|
|
@@ -853,7 +849,7 @@ export class ImapManager extends EventEmitter {
|
|
|
853
849
|
* so the server's connection slots free immediately rather than
|
|
854
850
|
* waiting for socket idle timeouts. */
|
|
855
851
|
async closeAllClients(accountId: string): Promise<void> {
|
|
856
|
-
for (const map of
|
|
852
|
+
for (const map of this.laneClients.values()) {
|
|
857
853
|
const c = map.get(accountId);
|
|
858
854
|
map.delete(accountId);
|
|
859
855
|
if (c) { try { await (c._realLogout || c.logout)(); } catch { /* */ } try { c.destroy?.(); } catch { /* */ } }
|
|
@@ -871,7 +867,7 @@ export class ImapManager extends EventEmitter {
|
|
|
871
867
|
/** Disconnect the persistent operational connections (both lanes) for
|
|
872
868
|
* an account. */
|
|
873
869
|
async disconnectOps(accountId: string): Promise<void> {
|
|
874
|
-
for (const [name, map] of
|
|
870
|
+
for (const [name, map] of this.laneClients) {
|
|
875
871
|
const client = map.get(accountId);
|
|
876
872
|
map.delete(accountId);
|
|
877
873
|
if (client) {
|
|
@@ -1383,8 +1379,16 @@ export class ImapManager extends EventEmitter {
|
|
|
1383
1379
|
// recent under stable UIDVALIDITY, so prefer newest when capping — the
|
|
1384
1380
|
// user cares most about recent mail and the deficit gate keeps calling
|
|
1385
1381
|
// us until the backlog is drained.
|
|
1382
|
+
//
|
|
1383
|
+
// Kept deliberately small (Bob 2026-06-20): each backfilled batch feeds
|
|
1384
|
+
// the body-prefetcher, which issues large UID FETCHes on the single
|
|
1385
|
+
// shared slow-lane connection. A 5000-message batch flooded that
|
|
1386
|
+
// connection (cmd-chain waits of 70s+, 90s FETCH timeouts) and wedged
|
|
1387
|
+
// the whole sync worker. A small batch per cycle keeps prefetch's queue
|
|
1388
|
+
// shallow so the connection stays responsive; the deficit gate drains
|
|
1389
|
+
// the backlog over more cycles instead of one connection-killing burst.
|
|
1386
1390
|
const BACKFILL_CHUNK_SIZE = 100;
|
|
1387
|
-
const RECONCILE_FETCH_CAP =
|
|
1391
|
+
const RECONCILE_FETCH_CAP = 1000;
|
|
1388
1392
|
let toFetch = missingUids;
|
|
1389
1393
|
if (missingUids.length > RECONCILE_FETCH_CAP) {
|
|
1390
1394
|
console.log(` ${folderPath}: ${missingUids.length} server-only UIDs — capped at ${RECONCILE_FETCH_CAP}; resumes next cycle`);
|
|
@@ -2516,12 +2520,15 @@ export class ImapManager extends EventEmitter {
|
|
|
2516
2520
|
return stored;
|
|
2517
2521
|
}
|
|
2518
2522
|
|
|
2519
|
-
/** Kill and recreate the persistent
|
|
2523
|
+
/** Kill and recreate the persistent connections for an account — drops the
|
|
2524
|
+
* client on every lane so the next task on each reconnects fresh. */
|
|
2520
2525
|
private async reconnectOps(accountId: string): Promise<void> {
|
|
2521
|
-
const
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2526
|
+
for (const map of this.laneClients.values()) {
|
|
2527
|
+
const old = map.get(accountId);
|
|
2528
|
+
map.delete(accountId);
|
|
2529
|
+
if (old) { try { await (old._realLogout || old.logout)(); } catch { /* */ } }
|
|
2530
|
+
}
|
|
2531
|
+
console.log(` [conn] ${accountId}: reconnecting (all lanes)`);
|
|
2525
2532
|
}
|
|
2526
2533
|
|
|
2527
2534
|
/** Handle sync errors — classify and emit appropriate UI events.
|
|
@@ -3554,7 +3561,7 @@ export class ImapManager extends EventEmitter {
|
|
|
3554
3561
|
})());
|
|
3555
3562
|
});
|
|
3556
3563
|
await Promise.all(pending);
|
|
3557
|
-
}, {
|
|
3564
|
+
}, { lane: "prefetch", timeoutMs: 300_000 });
|
|
3558
3565
|
// 5-min cap, not the 90s interactive default:
|
|
3559
3566
|
// prefetch is background, and a 25-message body
|
|
3560
3567
|
// chunk on a slow Dovecot legitimately runs past
|
|
@@ -4318,7 +4325,7 @@ export class ImapManager extends EventEmitter {
|
|
|
4318
4325
|
await this.withConnection(accountId, async (client) => {
|
|
4319
4326
|
await client.createmailbox("Outbox");
|
|
4320
4327
|
await this.syncFolders(accountId, client);
|
|
4321
|
-
});
|
|
4328
|
+
}, { lane: "outbox" });
|
|
4322
4329
|
} catch (e: any) {
|
|
4323
4330
|
// Might already exist — benign
|
|
4324
4331
|
if (!e.message?.includes("already exists")) throw e;
|
|
@@ -4429,7 +4436,7 @@ export class ImapManager extends EventEmitter {
|
|
|
4429
4436
|
await this.withConnection(accountId, async (client) => {
|
|
4430
4437
|
appendedUid = await client.appendMessage(outboxPath, rawMessage, ["\\Seen"]);
|
|
4431
4438
|
console.log(` [outbox] Queued message in ${outboxPath}${appendedUid != null ? ` (UID ${appendedUid})` : ""}`);
|
|
4432
|
-
});
|
|
4439
|
+
}, { lane: "outbox" });
|
|
4433
4440
|
if (outboxFolder) {
|
|
4434
4441
|
if (appendedUid != null) {
|
|
4435
4442
|
// Inserts the row from the source bytes we already have +
|
|
@@ -4636,7 +4643,9 @@ export class ImapManager extends EventEmitter {
|
|
|
4636
4643
|
// claim so the recovery sweeper picks it up next tick.
|
|
4637
4644
|
try {
|
|
4638
4645
|
const outboxPath = await this.ensureOutbox(accountId);
|
|
4639
|
-
|
|
4646
|
+
// Outbox lane, not the slow/sync lane — a wedged APPEND here (which
|
|
4647
|
+
// withTimeout force-closes the socket on) must not disrupt sync.
|
|
4648
|
+
const client = await this.getLaneClient(accountId, "outbox");
|
|
4640
4649
|
try {
|
|
4641
4650
|
for (const { dir, file } of filesToSend) {
|
|
4642
4651
|
const filePath = path.join(dir, file);
|
|
@@ -4772,9 +4781,9 @@ export class ImapManager extends EventEmitter {
|
|
|
4772
4781
|
const account = settings.accounts.find(a => a.id === accountId);
|
|
4773
4782
|
if (!account) return;
|
|
4774
4783
|
|
|
4775
|
-
// List UIDs first — quick command
|
|
4784
|
+
// List UIDs first — quick command on the dedicated outbox lane.
|
|
4776
4785
|
const uids = await this.withConnection(accountId, (client) =>
|
|
4777
|
-
client.getUids(outboxFolder.path)
|
|
4786
|
+
client.getUids(outboxFolder.path), { lane: "outbox" }
|
|
4778
4787
|
) as number[];
|
|
4779
4788
|
if (uids.length === 0) return;
|
|
4780
4789
|
|
|
@@ -4784,9 +4793,9 @@ export class ImapManager extends EventEmitter {
|
|
|
4784
4793
|
const sentFolder = this.findFolder(accountId, "sent");
|
|
4785
4794
|
|
|
4786
4795
|
for (const uid of uids) {
|
|
4787
|
-
// Each iteration is one
|
|
4788
|
-
//
|
|
4789
|
-
//
|
|
4796
|
+
// Each iteration is one outbox-lane turn — sync, prefetch and
|
|
4797
|
+
// fast-lane (click) work all run on their own connections, so a
|
|
4798
|
+
// long outbox drain never blocks them.
|
|
4790
4799
|
const result = await this.withConnection(accountId, async (client) => {
|
|
4791
4800
|
const flags = await client.getFlags(outboxFolder.path, uid);
|
|
4792
4801
|
|
|
@@ -4834,7 +4843,7 @@ export class ImapManager extends EventEmitter {
|
|
|
4834
4843
|
return { skip: true };
|
|
4835
4844
|
}
|
|
4836
4845
|
return { source: msg.source };
|
|
4837
|
-
}, {
|
|
4846
|
+
}, { lane: "outbox" });
|
|
4838
4847
|
|
|
4839
4848
|
if ((result as any).skip) continue;
|
|
4840
4849
|
const source = (result as any).source as string;
|
|
@@ -4850,13 +4859,13 @@ export class ImapManager extends EventEmitter {
|
|
|
4850
4859
|
await this.withConnection(accountId, async (client) => {
|
|
4851
4860
|
// Delete FIRST to prevent double-send if Sent-copy fails.
|
|
4852
4861
|
await client.deleteMessageByUid(outboxFolder.path, uid);
|
|
4853
|
-
}, {
|
|
4862
|
+
}, { lane: "outbox" });
|
|
4854
4863
|
if (sentFolder) {
|
|
4855
4864
|
let appendedSentUid: number | null = null;
|
|
4856
4865
|
try {
|
|
4857
4866
|
await this.withConnection(accountId, async (client) => {
|
|
4858
4867
|
appendedSentUid = await client.appendMessage(sentFolder.path, source, ["\\Seen"]);
|
|
4859
|
-
}, {
|
|
4868
|
+
}, { lane: "outbox" });
|
|
4860
4869
|
} catch (sentErr: any) {
|
|
4861
4870
|
console.error(` [outbox] Failed to copy to Sent: ${sentErr.message} — message was sent successfully`);
|
|
4862
4871
|
}
|
|
@@ -4886,7 +4895,7 @@ export class ImapManager extends EventEmitter {
|
|
|
4886
4895
|
await this.withConnection(accountId, async (client) => {
|
|
4887
4896
|
await client.removeFlags(outboxFolder.path, uid, [sendingFlag]);
|
|
4888
4897
|
await client.addFlags(outboxFolder.path, uid, ["$Failed"]);
|
|
4889
|
-
}, {
|
|
4898
|
+
}, { lane: "outbox" });
|
|
4890
4899
|
} catch { /* best-effort */ }
|
|
4891
4900
|
// Suppress the banner for transient network errors. ETIMEDOUT
|
|
4892
4901
|
// on a Dovecot send is the server being slow / a TCP idle
|
|
@@ -5025,10 +5034,10 @@ export class ImapManager extends EventEmitter {
|
|
|
5025
5034
|
this.outboxBackoffDelay.delete(accountId);
|
|
5026
5035
|
} catch (e: any) {
|
|
5027
5036
|
// Stale-socket errors (Dovecot silently drops idle connections,
|
|
5028
|
-
// or the sync path timed out and destroyed the socket): force
|
|
5029
|
-
// fresh
|
|
5030
|
-
// dead socket. Without reconnectOps, the dead client stays
|
|
5031
|
-
//
|
|
5037
|
+
// or the sync path timed out and destroyed the socket): force
|
|
5038
|
+
// fresh lane clients so the next tick doesn't keep hitting the
|
|
5039
|
+
// same dead socket. Without reconnectOps, the dead client stays
|
|
5040
|
+
// in its lane map and every subsequent processOutbox call fails
|
|
5032
5041
|
// immediately with "Not connected" — forever.
|
|
5033
5042
|
const msg = String(e?.message || e);
|
|
5034
5043
|
if (/Not connected|ECONNRESET|socket hang up|EPIPE|write after end/i.test(msg)) {
|
|
@@ -5128,19 +5137,18 @@ export class ImapManager extends EventEmitter {
|
|
|
5128
5137
|
if (rows.length === 0) return;
|
|
5129
5138
|
let reconciled = 0;
|
|
5130
5139
|
let appended = 0;
|
|
5131
|
-
//
|
|
5132
|
-
//
|
|
5133
|
-
//
|
|
5134
|
-
//
|
|
5135
|
-
//
|
|
5136
|
-
//
|
|
5137
|
-
//
|
|
5138
|
-
//
|
|
5139
|
-
//
|
|
5140
|
-
//
|
|
5141
|
-
//
|
|
5142
|
-
|
|
5143
|
-
try {
|
|
5140
|
+
// Run the whole sweep on the dedicated "outbox" lane — its OWN
|
|
5141
|
+
// persistent connection, separate from the slow/sync lane. Two reasons:
|
|
5142
|
+
// 1. Sent-sweep's `SELECT Sent` has been observed taking 90s on this
|
|
5143
|
+
// server; on the shared slow lane that stalled INBOX sync/backfill
|
|
5144
|
+
// behind it (the "whole worker goes silent" wedge, Bob 2026-06-20).
|
|
5145
|
+
// 2. withConnection serializes the entire SEARCH→APPEND sweep on one
|
|
5146
|
+
// connection, so it can't interleave mid-transaction with another
|
|
5147
|
+
// task's SELECT (the "BAD No mailbox selected" class, Bob
|
|
5148
|
+
// 2026-05-25). Previously this used createClientWithLimit() — which
|
|
5149
|
+
// actually returned the SHARED slow client and then destroyed it in
|
|
5150
|
+
// a finally, the opposite of "dedicated".
|
|
5151
|
+
await this.withConnection(accountId, async (client) => {
|
|
5144
5152
|
for (const row of rows) {
|
|
5145
5153
|
const msgId = row.message_id;
|
|
5146
5154
|
if (!msgId) continue;
|
|
@@ -5177,10 +5185,7 @@ export class ImapManager extends EventEmitter {
|
|
|
5177
5185
|
}
|
|
5178
5186
|
}
|
|
5179
5187
|
}
|
|
5180
|
-
}
|
|
5181
|
-
try { await (client._realLogout || client.logout)(); } catch { /* */ }
|
|
5182
|
-
try { client.destroy?.(); } catch { /* */ }
|
|
5183
|
-
}
|
|
5188
|
+
}, { lane: "outbox", timeoutMs: 120_000 });
|
|
5184
5189
|
if (reconciled + appended > 0) {
|
|
5185
5190
|
this.emit("folderCountsChanged", accountId, {});
|
|
5186
5191
|
console.log(` [sent-sweep] ${accountId}: ${reconciled} rebound, ${appended} re-appended`);
|
|
@@ -5461,13 +5466,13 @@ export class ImapManager extends EventEmitter {
|
|
|
5461
5466
|
this.stopPeriodicSync();
|
|
5462
5467
|
this.stopOutboxWorker();
|
|
5463
5468
|
await this.stopWatching();
|
|
5464
|
-
// Disconnect persistent connections on
|
|
5465
|
-
// because
|
|
5466
|
-
//
|
|
5467
|
-
const accountIds = new Set<string>(
|
|
5468
|
-
|
|
5469
|
-
|
|
5470
|
-
|
|
5469
|
+
// Disconnect persistent connections on every lane. Union across all
|
|
5470
|
+
// lane maps because a lane can hold an account the others don't (e.g.
|
|
5471
|
+
// body fetches happened on "fast" but no sync ran on "sync").
|
|
5472
|
+
const accountIds = new Set<string>();
|
|
5473
|
+
for (const map of this.laneClients.values()) {
|
|
5474
|
+
for (const k of map.keys()) accountIds.add(k);
|
|
5475
|
+
}
|
|
5471
5476
|
for (const accountId of accountIds) {
|
|
5472
5477
|
await this.disconnectOps(accountId);
|
|
5473
5478
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bobfrankston/mailx-imap",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.105",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@bobfrankston/mailx-imap",
|
|
9
|
-
"version": "0.1.
|
|
9
|
+
"version": "0.1.105",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@bobfrankston/iflow-direct": "^0.1.27",
|