node-red-node-email: uncaught TypeError 'fetchCache' in imap crashes the Node-RED runtime
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- javascript, nodejs
- 領域
- backend
調査の方向性
The crash comes from the bundled imap dependency at node_modules/node-red-node-email/node_modules/imap/lib/Connection.js, around lines 196-197, where the 'body' handler reads self._curReq.fetchCache without checking _curReq. Start by reading that handler and the Parser callbacks the stack trace names. Done means an unsolicited FETCH body is drained and ignored without throwing, and the maintainers have agreed whether the fix goes in as a guard, a patch, or a dependency change.
索引モデルが issue の本文から書いたものです。
説明
Which node are you reporting and issue on?
node-red-node-email (e-mail in, IMAP)
What are the steps to reproduce?
Add an e-mail in node with this configuration:
Protocol: IMAP, server imap.gmail.com, port 993, SSL on, Start TLS: never, Auth: Basic
Folder: INBOX, Criteria: UNSEEN, Disposition: None
Fetch: automatically, every 420 s
Deploy and leave it running.
After some time, Node-RED crashes. It happens intermittently, after several hours of polling.
What happens?
An uncaught exception inside the bundled imap dependency stops the whole Node-RED process, not just the node:
[red] Uncaught Exception:
[error] TypeError: Cannot read properties of undefined (reading 'fetchCache')
at Parser.<anonymous> (/data/node_modules/node-red-node-email/node_modules/imap/lib/Connection.js:197:28)
at Parser.emit (node:events:514:28)
at Parser._resUntagged (/data/node_modules/node-red-node-email/node_modules/imap/lib/Parser.js:196:10)
at Parser._parse (/data/node_modules/node-red-node-email/node_modules/imap/lib/Parser.js:137:16)
at Parser._tryread (/data/node_modules/node-red-node-email/node_modules/imap/lib/Parser.js:82:15)
at Parser._cbReadable (/data/node_modules/node-red-node-email/node_modules/imap/lib/Parser.js:53:12)
at TLSSocket.emit (node:events:514:28)
at emitReadable_ (node:internal/streams/readable:845:12)
at process.processTicksAndRejections (node:internal/process/task_queues:89:21)
Root cause: [email protected], which this package pins, has this code in lib/Connection.js:196-197:
parser.on('body', function(stream, info) {
var msg = self._curReq.fetchCache[info.seqno], toget;
The server can send an untagged FETCH that carries a body literal when no command is in flight, so self._curReq is undefined. This happens with Gmail after a fetch completed, timed out, or the connection was re-established. The handler does not check _curReq, and the error is thrown inside a TLSSocket read callback. An imap.on('error') listener therefore cannot catch it, and Node-RED treats it as an uncaught exception. imap (mscdex/node-imap) has not been released since 2016, so a fix upstream is unlikely.
Proposed fix (low risk): guard the handler. Drain the stray literal so the parser stays in sync, then drop it:
parser.on('body', function(stream, info) {
if (!self._curReq || !self._curReq.fetchCache) {
stream.resume(); // unsolicited FETCH body: consume and ignore
return;
}
var msg = self._curReq.fetchCache[info.seqno], toget;
The fix could ship either by applying the guard with patch-package in postinstall, or by switching the dependency to a maintained fork of imap that already guards _curReq. A longer-term option is to migrate the IMAP input to imapflow. It is maintained and reports protocol errors as promise rejections instead of throwing from socket callbacks.
Workaround: apply the guard by hand in node_modules/node-red-node-email/node_modules/imap/lib/Connection.js and restart Node-RED. The change is lost on every reinstall.
What did you expect to happen?
An unexpected server response should at most raise a node error or status, and the node should reconnect. It should never take down the runtime and every other flow running in it.
Example flow
paste your flow here
Environment
- Node-RED version: 5.0.8 (official docker container)
node -v && npm -v
v24.21.0
11.21.0 - Platform/OS: Docker, official
nodered/node-redimage - Browser: n/a (runtime crash)
- node-red-node-email version: node-red-node-email 5.2.5
- imap version: 0.8.19
- IMAP server: imap.gmail.com:993
- 主要言語
- JavaScript
- スター
- 1.1k
- フォーク
- 610
- 平均マージ
- 1日 4時間
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
node-red/node-red-nodes のほかの issue
-
難易度 3/5 半日 初心者へのやさしさ 42/100
node-red/node-red-nodes#1152 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
node-red/node-red-nodes#1142 · コメント 11 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
node-red/node-red-nodes#1141 · コメント 15 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
node-red/node-red-nodes#1130 · コメント 4 件 ·
-
dependencies
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
node-red/node-red-nodes#1121 · コメント 5 件 ·
node-red/node-red-nodes の issue をすべて見る
似ている issue
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
andromarces/agent-loops#886 ·
メンテナーはふだん 1 日以内に返信
-
bug effort:low model:light plan planner:gpt-6-1-sol tests
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
B: visual
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
FreeTubeApp/FreeTube#9929 ·
メンテナーはふだん 1 日以内に返信
-
🐛 Bug: `--clear-screen` not very useful (at least not for dealing with large test/error output)オープンstatus: in triage type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
mochajs/mocha#6428 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
supabase/supabase-js#2768 ·
メンテナーはふだん 1 日以内に返信