fix(imap): attach error/close handlers to prevent silent exit on idle drops#29
Open
elcamino666 wants to merge 1 commit into
Open
fix(imap): attach error/close handlers to prevent silent exit on idle drops#29elcamino666 wants to merge 1 commit into
elcamino666 wants to merge 1 commit into
Conversation
Without listeners, an idle IMAP connection that the server later drops emits an error event with no listener. Node treats that as an uncaughtException and silently exits the process. Because logger is false, there is no trace in the MCP log: the server simply disappears mid-session and the client reports the tools as disconnected with no obvious cause. Most hosted providers close IDLE sessions after about 29 minutes (reproduced against Hostinger), which produced a reliable silent-exit roughly 30 minutes into a session. Attach error and close handlers before client.connect: - Log the error via mcpLog (catching the promise so the handler itself cannot throw). - Drop the cached client so the next getImapClient call reconnects through the existing usable check. No behavior change on healthy connections; idle drops now self-heal instead of crashing the process.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ConnectionManager.getImapClientcreates anImapFlowclient without attachingerrororcloselisteners. When the IMAP server drops an idle connection — which most hosted providers do after ~29 minutes (Hostinger in our case) — ImapFlow emitserror. With no listener, Node treats it asuncaughtExceptionand exits the process.Because the client is constructed with
logger: false, nothing is written to stderr. From the user's perspective the MCP server simply disappears mid-session and Claude Code / Cursor reports the tools as deferred/disconnected with no trace in the MCP log.We hit this reproducibly on Hostinger: every session went silent ~30 minutes after the last successful tool call. Log file showed clean tool calls then nothing — no error, no shutdown line.
Fix
Attach
errorandclosehandlers beforeclient.connect()so we never miss an event:error: log viamcpLog(catching its promise so the handler itself cannot throw) and drop the cached client.close: drop the cached client.The next
getImapClient()call then reconnects via the existingusablecheck — exactly the auto-reconnect behaviour the file's docstring already promises.Impact
Verification
npm run build— cleannpm run lint— cleannpm test— 150/150 passOpen to feedback on log level (
warningvsinfo) or whether the close handler should also log.