Skip to content

Fix infinite $ref resolution loops#1195

Merged
datho7561 merged 2 commits intoredhat-developer:mainfrom
shin19991207:patch-1190
Feb 25, 2026
Merged

Fix infinite $ref resolution loops#1195
datho7561 merged 2 commits intoredhat-developer:mainfrom
shin19991207:patch-1190

Conversation

@shin19991207
Copy link
Member

What does this PR do?

yamlSchemaService could keep expanding references forever and crash with heap/stack OOM when resolving schema with cyclic references.

Original implementation introduces a bug when $ref + siblings are rewritten to allOf and creates new nodes. This can cause dynamic ref paths to revisit the same resource repeatedly.

Fixed by:

  • Added sibling cycle tracking in traversal state in WalkItem.siblingRefCycleKeys
  • Stop rewriting when the same sibling-ref target is seen again
  • Added a helper to short-circuit when a target resource is already in resolutionStack
  • Changed local merge cloning to only clone for local $dynamicRef with dynamic scope

What issues does this PR fix or reference?

Fixes #1190

Is it tested? How?

Automated test and manually with this example:

# yaml-language-server: $schema=https://raw.githubusercontent.com/OAI/spec.openapis.org/refs/heads/main/oas/3.1/schema/2025-11-23
openapi: "3.1.0"
info:
  version: 1.0.0
  title: Minimal ping API server
paths:
  /ping:
    get:
      responses:
        "200":
          description: pet response
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pong"
components:
  schemas:
    # base types
    Pong:
      type: object
      required:
        - ping
      properties:
        ping:
          type: string
          example: pong

When triggering auto-completion, expected to see 'no suggestion' instead of no response (keep loading).

Signed-off-by: Morgan Chang <shin19991207@gmail.com>
Copy link
Contributor

@datho7561 datho7561 left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks, Morgan!

@datho7561 datho7561 merged commit ce38c3b into redhat-developer:main Feb 25, 2026
4 checks passed
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.

yaml-language-server loads forever and crashes with out of memory error

2 participants