RocketChat/Rocket.Chat · error

Fetch error

Error message

Fetch error

What it means

The IMAP interceptor's batch fetch (imap.fetch over a set of message ids, requesting HEADER/TEXT bodies and structure) emitted an 'error' event. Unlike the per-message flag warning, this handler rejects the enclosing promise, so the whole poll cycle for those emailIds fails and the caller of getEmails receives the rejection. Typical causes are a dropped connection mid-fetch, sequence numbers invalidated by concurrent mailbox changes, or server-side timeouts.

Source

Thrown at apps/meteor/server/email/IMAPInterceptor.ts:202

					simpleParser(new Readable().wrap(stream), (_err, email) => {
						if (this.options.rejectBeforeTS && email.date && email.date < this.options.rejectBeforeTS) {
							logger.error({ msg: 'Rejecting email on inbox', user: this.config.user, subject: email.subject });
							return;
						}
						this.emit('email', email);
						if (this.options.deleteAfterRead) {
							this.imap.seq.addFlags(email, 'Deleted', (err) => {
								if (err) {
									logger.warn({ msg: 'Mark deleted error', err });
								}
							});
						}
					});
				};
				msg.once('body', bodycb);
			};
			const errorcb = (err: Error): void => {
				logger.warn({ msg: 'Fetch error', err });
				reject(err);
			};
			const endcb = (): void => {
				resolve(out);
			};
			const fetch = this.imap.fetch(emailIds, {
				bodies: ['HEADER', 'TEXT', ''],
				struct: true,
				markSeen: this.options.markSeen,
			});

			fetch.on('message', messagecb);
			fetch.on('error', errorcb);
			fetch.on('end', endcb);
		});
	}

	// Fetch all UNSEEN messages and pass them for further processing

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Read the err text for 'BYE', 'timeout', or 'Connection error' to classify it
  2. Reduce fetch batch size and poll frequency
  3. Ensure only one consumer processes the mailbox
  4. Make the polling loop catch the rejection, reconnect, and retry with backoff instead of dying
Defensive patterns

Strategy: retry

Try / catch

try {
	const ids = await interceptor.getEmails();
} catch (error) {
	logger.warn({ msg: 'IMAP fetch failed, reconnecting', err: error });
	await interceptor.reconnect();
	// retry the batch once after reconnect; then back off
}

Prevention

When it happens

Trigger: Connection reset while streaming message bodies; another client expunging messages so sequence numbers shift under the running fetch; fetching a very large backlog exceeding the server's command timeout; server sending BYE due to inactivity/throttling.

Common situations: Inbound-email channel against shared IMAP hosts with aggressive timeouts; two consumers (Rocket.Chat plus a mail client) working the same mailbox; first connect after downtime fetching a huge backlog.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/813b85a877814bbb. Report an issue: GitHub.