Skip to content

Commit b749f96

Browse files
committed
fix: Memory leak fixes for IMAP client and webhooks worker
- Clear reconnectTimer in imap-client.js close() and delete() methods to prevent timer references keeping objects in memory after account removal - Drain HTTP response body in webhooks.js on error responses to release connections back to undici connection pool
1 parent b001fc9 commit b749f96

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/email-client/imap-client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,7 @@ class IMAPClient extends BaseClient {
15011501
clearTimeout(this.untaggedExpungeTimer);
15021502
clearTimeout(this.resyncTimer);
15031503
clearTimeout(this.completedTimer);
1504+
clearTimeout(this.reconnectTimer);
15041505

15051506
try {
15061507
// Clean up all mailboxes
@@ -1544,6 +1545,7 @@ class IMAPClient extends BaseClient {
15441545
clearTimeout(this.untaggedExpungeTimer);
15451546
clearTimeout(this.resyncTimer);
15461547
clearTimeout(this.completedTimer);
1548+
clearTimeout(this.reconnectTimer);
15471549

15481550
this.isClosing = false;
15491551
this.isClosed = true;

workers/webhooks.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,12 @@ const notifyWorker = new Worker(
411411
}
412412

413413
if (!res.ok) {
414+
// Drain response body to release connection back to pool
415+
try {
416+
await res.text();
417+
} catch {
418+
// ignore drain errors
419+
}
414420
let err = new Error(res.statusText || `Invalid response: ${res.status} ${res.statusText}`);
415421
err.statusCode = res.status;
416422
throw err;

0 commit comments

Comments
 (0)