Skip to content

fix: prevent infinite recursion for circular tuple array schemas#2438

Open
Varadraj75 wants to merge 2 commits intoasyncapi:masterfrom
Varadraj75:fix/circular-tuple-array-recursion
Open

fix: prevent infinite recursion for circular tuple array schemas#2438
Varadraj75 wants to merge 2 commits intoasyncapi:masterfrom
Varadraj75:fix/circular-tuple-array-recursion

Conversation

@Varadraj75
Copy link
Contributor

Description

Fixes infinite recursion when processing circular tuple-based array schemas
by correctly propagating the recursion guard during tuple item conversion.

Includes a minimal, safe change with no behavioral impact on non-circular schemas.

Related Issue

Fixes #2436

Checklist

  • The code follows the project's coding standards and is properly linted (npm run lint).
  • Tests have been added or updated to cover the changes.
  • Documentation has been updated to reflect the changes.
  • All tests pass successfully locally.(npm run test).

Additional Notes

NONE

Copilot AI review requested due to automatic review settings February 9, 2026 13:21
@netlify
Copy link

netlify bot commented Feb 9, 2026

Deploy Preview for modelina canceled.

Name Link
🔨 Latest commit 4a6f293
🔍 Latest deploy log https://app.netlify.com/projects/modelina/deploys/698b6b6eb743d10008c892e0

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a stack overflow caused by infinite recursion when converting circular tuple-based array schemas in AsyncAPIInputProcessor.convertToInternalSchema() by properly propagating the recursion guard map during tuple item conversion.

Changes:

  • Propagate alreadyIteratedSchemas into convertToInternalSchema() calls for tuple-array items during .map().
  • Prevent infinite recursion for circular schemas embedded inside tuple-array items (fixes #2436).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coveralls
Copy link

coveralls commented Feb 9, 2026

Pull Request Test Coverage Report for Build 21875539290

Details

  • 3 of 4 (75.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 90.998%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/processors/AsyncAPIInputProcessor.ts 3 4 75.0%
Totals Coverage Status
Change from base Build 21874638391: 0.001%
Covered Lines: 6942
Relevant Lines: 7421

💛 - Coveralls

@Varadraj75
Copy link
Contributor Author

Hi @jonaslagoni ,

All checks are passing now and the fix is ready for review.
This PR propagates the existing recursion guard to tuple-array item processing, preventing infinite recursion for circular schemas with a minimal and safe change.

Whenever you get a moment, could you please take a look?
Thanks a lot!

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

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

Always make sure to add tests that show the error you found and that now passes 🙂

@Varadraj75
Copy link
Contributor Author

@jonaslagoni ,
i have added the test, please review it , do let me know if there is any other changes.
thanks!

Comment on lines 205 to 211
if (typeof schema === 'object') {
if (visitedSchemas.has(schema)) {
return {};
}
visitedSchemas.add(schema);
}

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jonaslagoni, thanks for pointing this out

Good catch — this was duplicated unintentionally while wiring the recursion guard into tuple item conversion. The logic already exists later in the function, so re-adding it here isn’t necessary.

I’ve now refactored it to reuse the existing recursion-guard handling instead of duplicating it, keeping the behavior unchanged while avoiding redundancy.

Please let me know if this looks good now or if you’d prefer a different structure here. Thanks!

@Varadraj75 Varadraj75 force-pushed the fix/circular-tuple-array-recursion branch 2 times, most recently from ee5ea95 to 6d8cba8 Compare February 10, 2026 14:46
@Varadraj75 Varadraj75 force-pushed the fix/circular-tuple-array-recursion branch from 6d8cba8 to bd1494e Compare February 10, 2026 14:55
@sonarqubecloud
Copy link

Copy link
Member

@jonaslagoni jonaslagoni left a comment

Choose a reason for hiding this comment

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

Anything from this code that does not make sense?

@Varadraj75
Copy link
Contributor Author

@jonaslagoni thanks for the follow-up

I’ve gone through the updated code once more, especially around the recursion guard handling and tuple item conversion, and everything looks consistent to me now.

The duplicated guard logic has been removed, the existing guard is reused correctly, and the added test reproduces the original issue and passes with the fix in place. I don’t see anything remaining that doesn’t make sense or could be simplified further without changing behavior.

Happy to adjust if you spot anything specific or would like a different structure — thanks again for the detailed review.

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.

[BUG] Infinite recursion causes stack overflow for circular tuple schemas in AsyncAPIInputProcessor

3 participants