Skip to content

fix: stop flattenError at a cyclic error cause - #393

Open
ofri-peretz wants to merge 1 commit into
EventSource:mainfrom
ofri-peretz:fix/cyclic-error-cause
Open

ofri-peretz wants to merge 1 commit into
EventSource:mainfrom
ofri-peretz:fix/cyclic-error-cause

Conversation

@ofri-peretz

Copy link
Copy Markdown

flattenError follows err.cause (and err.errors) with no stop. If fetch() rejects with an error whose cause chain loops back on itself, it throws RangeError: Maximum call stack size exceeded inside the failure handler. The rejection goes unhandled, no error event fires, and the reconnect is never scheduled.

The fix passes a set of errors already flattened through the recursion and stops at one it has seen. It also stops passing map's index as a second argument. There's a new test with a fetch that rejects with a cyclic cause. It fails with the RangeError before the change, and the whole suite passes after.

I found this with no-unbounded-cause-recursion from eslint-plugin-reliability, a plugin I maintain. The patch was prepared with an AI assistant (Claude Code). I reviewed it and ran the tests.

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.

1 participant