Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circular reference in OpenAPI spec causes a stack overflow #132

Open
1 task done
umeshkumhar opened this issue Jan 29, 2024 · 3 comments
Open
1 task done

Circular reference in OpenAPI spec causes a stack overflow #132

umeshkumhar opened this issue Jan 29, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@umeshkumhar
Copy link

tfplugingen-openapi CLI version

tfplugingen-openapi module: v0.3.0

OpenAPI Spec File

https://gist.github.com/umeshkumhar/97c7888fbcf6f294bb54210e0faec918

Generator Config

provider:
  name: backupdr

resources:
  slp:
    create:
      path:  /slp
      method: POST
    read:
      path:  /slp
      method: GET

Expected Behavior

It should have generated provider spec json.

Actual Behavior

This just executed and later on get killed due to OOM (i guess). in some iteration it shows stack overflow error. The activity monitor states that it consumes 70+GB memory, please find the attached screenshot below. Seems like its failing during Marshalling the openapi file.
Screenshot 2024-01-29 at 10 16 38
Screenshot 2024-01-29 at 10 19 40

Additional Information

Please suggest some workaround this.. if we can still generate some provider spec json for at least /slt, /sla, /slp. to kickstart.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@umeshkumhar umeshkumhar added the bug Something isn't working label Jan 29, 2024
@austinvalle
Copy link
Member

Hey there @umeshkumhar 👋🏻, thanks for the detailed bug report and sorry you're running into trouble here.

I took a quick look at your OpenAPI spec and I believe the root issue is coming from some circular references in the spec. Currently our tooling doesn't throw an error if a circular reference exists, however, the current logic for building a schema assumes there are no circular references (which should be adjusted).

There are a couple things we'll need to consider for the tfplugingen-openapi tool here:

  • Currently the only circular references detected are "infinite loops", where the circular reference property is marked as required. (which there are not any in your OpenAPI spec, otherwise you would have gotten a warning message)
  • If we detect any circular reference, we'll need to determine if tfplugingen-openapi can actually handle them. Perhaps by attempting to skip said circular reference properties.

Locally I adjusted the logic to print out all the circular references found in the OpenAPI spec you provided:

time=2024-01-29T15:21:14.346-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="BackupNowRest -> PolicyRest -> SourceRest -> SlpRest -> DiskPoolRest -> DiskPoolCopiesRest -> CloudCredentialRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="BackupNowRest -> PolicyRest -> SourceRest -> SlpRest -> DiskPoolRest -> DiskPoolCopiesRest -> CloudCredentialRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="BackupNowRest -> PolicyRest -> SourceRest -> SlpRest -> DiskPoolRest -> DiskPoolCopiesRest -> CloudCredentialRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="BackupNowRest -> PolicyRest -> SourceRest -> HostRest -> SourceRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="BackupNowRest -> PolicyRest -> SourceRest -> HostRest -> HostRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="BackupNowRest -> PolicyRest -> SltRest -> AdvancedOptionRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="BackupNowRest -> PolicyRest -> SltRest -> AdvancedOptionRest -> SltRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="BackupNowRest -> PolicyRest -> SltRest -> AdvancedOptionRest -> SlaRest -> AdvancedOptionRest -> LogicalGroupRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="BackupNowRest -> PolicyRest -> SltRest -> AdvancedOptionRest -> SlaRest -> AdvancedOptionRest -> LogicalGroupRest -> ExportVolumeInfoRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="BackupNowRest -> PolicyRest -> SltRest -> AdvancedOptionRest -> SlaRest -> AdvancedOptionRest -> LogicalGroupRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="BackupNowRest -> PolicyRest -> SltRest -> AdvancedOptionRest -> SlaRest -> AdvancedOptionRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="MountRest -> SystemStateOptionRest -> SystemStateOptionRest"
time=2024-01-29T15:21:14.347-05:00 level=WARN msg="circular reference found in OpenAPI spec" circular_ref="SessionRest -> UserRest -> RightRest -> RightRest"

I will spend some time investigating what we can do here 👍🏻

@austinvalle
Copy link
Member

Also worth noting here that Terraform resource/data source schemas don't support a notion of a recursive schema, so the final solution may end up behind some form of skip/controlled depth configuration.

At the very least, an explicit error should be returned in a case where we can't create a schema due to a circular reference.

@austinvalle austinvalle changed the title Getting Stack Overflow Circular reference in OpenAPI spec causes a stack overflow Jan 29, 2024
@hegerdes
Copy link

Was also facing this issue when i tested out this tool using the keycloak openapi. Most likely also caused by a recursive schema.

It chews up memory binging the whole system down if not killed. A informative error message would be very helpful as long as recursive schemas are not supported. It might also be sensible to add some safety nets for unsupported/unexpected configs. Like setting a max execution time or detect if things go wrong and just crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants