fix(serverless-offline-sqs): isolate poll-loop receive failures so they don't kill the process (Fixes #226)#290
Merged
Conversation
…ey don't kill the process (Fixes #226) A transient ReceiveMessage/SQS-client failure escaped the job() try/catch and the floating queue.add(job) promise went unhandled, terminating serverless offline. Move getMessages() inside the try and re-enqueue through a new pure enqueueLoop helper that .catch()es the p-queue task into log.warning. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #226
What / why
Reported by @newtechfellas: uncaught errors in the SQS poll loop terminate the
serverless offlineNode process, unlike API Gateway handler errors. Handler throws were already isolated (the #265 threaded-logger work), but the poll loop still had two leak paths: theReceiveMessagelong-poll (getMessages()) sat outsidejob()'s try/catch, and the re-enqueuethis.queue.add(job)was a floating promise never.catch()ed. p-queue rejects that promise when the task throws, so a transient SQS-client / network failure during receive became an unhandled promise rejection that killed the process.This moves
getMessages()inside the try (a receive failure is now logged vialog.warningand the loop re-schedules, exactly like a thrown handler) and routes both enqueue calls through a new pure, exportedenqueueLoop(queue, task, log)helper that.catch()es the p-queue task into the injected logger. Happy-path delivery (receive → run handler → delete batch) is byte-for-byte unchanged.Credit
Thanks to @newtechfellas for the report.
Verification
Failing AVA repro written first (2 unhandled rejections,
warnings.length === 0) and confirmed to FAIL onorigin/master. After the fix:npx ava packages/serverless-offline-sqs/test/index.js→ 124 passed (7 new #226 tests),npx eslintclean. Independently re-run by the orchestrator: green. All unit-level (AWS client mocked); no docker.Reviewer note (non-blocking, out of scope)
Under a persistent connection-refused emulator, the loop now warns in a tight busy-loop (no back-off). Strictly safer than master's process termination; an inter-poll back-off is a possible follow-up.
🤖 Generated with Claude Code