Skip to content

fix(api): await crawl-status-ws send to avoid unhandledRejection - #4253

Open
edenbuilds wants to merge 2 commits into
firecrawl:mainfrom
edenbuilds:fix/crawl-status-ws-await-send-4243
Open

edenbuilds wants to merge 2 commits into
firecrawl:mainfrom
edenbuilds:fix/crawl-status-ws-await-send-4243

Conversation

@edenbuilds

@edenbuilds edenbuilds commented Aug 6, 2026 •

Copy link
Copy Markdown

Summary

  • Await and .catch() document send() calls in the crawl-status-ws polling loops (v1 + v2) so a WebSocket close racing the ws.send callback cannot escape as unhandledRejection (Node 15+ process exit).
  • Make send() always return a Promise (resolve when readyState !== OPEN) so await send(...).catch(...) is safe when the socket is already closed — the late-close case this PR targets.

Test plan

  • Minimal harness: fire-and-forget send → unhandled >= 1; await send(...).catch(() => {}) → unhandled === 0.
  • Closed-socket path: send() with readyState !== 1 returns a thenable; await send(...).catch(() => {}) does not throw TypeError.

Fixes #4243

Document sends in the polling loop discarded send()'s Promise. A
socket close racing the ws.send callback rejected with no handler and
could terminate Node 15+. Await and catch both v1 and v2 loops.

Fixes firecrawl#4243
@edenbuilds
edenbuilds requested a review from mogery as a code owner August 6, 2026 23:22

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

When the socket is not OPEN, send() returned undefined, so
await send(...).catch() threw TypeError and reintroduced
unhandledRejection on the fire-and-forget polling loop.

Fixes cubic P1 on firecrawl#4253.
@edenbuilds

Copy link
Copy Markdown
Author

Fixed cubic P1: send() now always returns a Promise (Promise.resolve(null) when the socket is not OPEN), so await send(...).catch(() => {}) in both v1 and v2 polling loops no longer throws when the socket closes between loop iterations.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Re-trigger cubic

@edenbuilds

Copy link
Copy Markdown
Author

cubic approved this and it is still mergeable against current main. The only red check is the Vercel fork deployment gate. Is anything else needed from me before merge?

This branch has not been deployed

No deployments
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.

api: unawaited send() calls in crawl-status-ws polling loop cause unhandledRejection — crashes Node 15+ process on socket close

1 participant