Skip to content

Reject openConnection when CAPABILITY fails after greeting - #30

Merged
josefjadrny merged 1 commit into
masterfrom
UN-1360-handle-capability-rejection
Sep 29, 2026
Merged

josefjadrny merged 1 commit into
masterfrom
UN-1360-handle-capability-rejection

Conversation

@josefjadrny

@josefjadrny josefjadrny commented Sep 29, 2026 •

Copy link
Copy Markdown

Description

When an IMAP server sends its greeting and then closes the socket while the initial CAPABILITY command is pending, openConnection() left the updateCapability() promise without a rejection handler. The rejection (Socket closed unexpectedly!, command: "CAPABILITY") escaped as an unhandledRejection, which crashes consumers that treat unhandled rejections as fatal.

Fix: .catch(reject) on updateCapability() in openConnection(), so connect() rejects normally and callers can handle it.

dist/client.js is patched by hand for that one line. A full npm run build with the current toolchain rewrites all of dist/ with unrelated Babel helper changes.

What type of PR is this?

  • 🐛 Bug Fix

Manual testing

Ran a local TCP server that sends * OK hello and closes the socket on receiving CAPABILITY, then called client.connect() against dist/client.js:

  • master: connect() rejects and an UNHANDLED REJECTION: Socket closed unexpectedly! command=CAPABILITY is emitted
  • this branch: connect() rejects cleanly, no unhandled rejection

Added automated tests?

  • 👍 Unit tests added
  • 👍 Functional tests added
  • 🙅 No, because they are not applicable

The new test in #openConnection fails on master with Uncaught Error: Socket closed unexpectedly! and passes with the fix (70/70 unit tests).

Updated documentation?

  • 📜 README.md
  • 🙅 N/A

🤖 Generated with Claude Code

If the server sends a greeting and then closes the socket while the
initial CAPABILITY command is pending, the updateCapability() promise
rejected with no handler, surfacing as an unhandledRejection
("Socket closed unexpectedly!", command=CAPABILITY) that crashes
pmailer-syncer-imap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@josefjadrny

Copy link
Copy Markdown
Author

/review

@josefjadrny josefjadrny changed the title UN-1360: Reject openConnection when CAPABILITY fails after greeting Reject openConnection when CAPABILITY fails after greeting Sep 29, 2026
@josefjadrny

Copy link
Copy Markdown
Author

/review

will not work in public repo

@josefjadrny
josefjadrny merged commit bd770c7 into master Sep 29, 2026
@josefjadrny
josefjadrny deleted the UN-1360-handle-capability-rejection branch September 29, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants