-
Notifications
You must be signed in to change notification settings - Fork 6k
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
OutOfMemoryError #6394
Comments
I was able to repeat the issue with similar errors:
I'll take a deeper look tomorrow by investigating the spec. |
@wing328 The issue is in I suspect a fix may be to simply cap the number of items in an example array - there's probably not much value in a 2 billion item example. |
I've hit this with the javascript language. Had to revert to v2.2.2 because v2.2.3 is broken because of #5845 |
@dariota thanks for pointing out the exact root cause of the issue. May I know if you've time to contribute a PR with the fix? |
Not until mid January, but I can take it up then. |
typescript-angular same issue |
Python codegen same issue Affected versions:
|
according to my test (MacOS 10.13.3)
The simple code to test the Obejct array size limit: public class ObjectArraySizeTestHighXmx {
public static void main(String args[]) {
Integer arrayLength = Integer.MAX_VALUE;
Object[] objectProperties = null;
// objectProperties = new Object[2396729];
// System.out.print(objectProperties.length);
// step = 1
for (int i=arrayLength; i>1;i=i-1) {
try {
objectProperties = new Object[i];
} catch (OutOfMemoryError e) {
System.out.print("Out of memory: " + String.valueOf(i) + "\n");
// System.out.print(e.toString());
}
if (objectProperties != null) {
System.out.print("Find the limit by step 1: " + String.valueOf(i) + "\n");
System.out.print(objectProperties.length + "\n");
break;
}
}
}
} run javac ObjectArraySizeTestHighXmx.java
java -Xmx9g ObjectArraySizeTestHighXmx > ObjectArraySizeTestHighXmx-xmx9g.log the log file will be
|
I don't see why we shouldn't limit the size of the example - what benefit would you get from looking at a 2 billion item example array (with just generated default data in it) that you wouldn't get from a 10,000 (or even 100) item array? Of course, it would be nice to replace this in-memory creation of a massive array with a lazily generated array that's written as it's produced and massively reduces the memory footprint, but you'd still have an absolutely gigantic file for little to no value (bonus points when you try to view it and crash your browser). |
@dariota Yes, I also think it is not necessary to use large size of example array here. But do you think is it better to hardcode a size in here? or is there any mechanism to define this size? |
For maximal configurability it should be something the user can set (with a sensible default), but at the same time I'm not a big fan of excessive numbers of options overwhelming users. As a short-term fix, hardcoding a size will let the people having this issue actually use the specs they're trying to use. I'd argue for inclusion of a warning when the number of examples is reduced (or noting the max more directly in the generated output when the count's reduced). Longer term, pending determination of whether a config option to set the max number of items in the example should be added, a proper fix should be done, perhaps replacing the generation of an array with something like an Iterator that generates the output on the fly when the file's being written, to enable these huge examples should people want them (and choose to do so via the option) for some strange reason. |
Please file a PR with the suggested fix. My first suggestion is to use LOGGER.warn to show a warning message so that users will be notified of the issue. |
ok, I will submit a quick PR for this then we can discuss it further. |
Turns out the spec I was using (which was auto generated with int arrayLength = null == ((ArrayProperty) property).getMaxItems() ? 2 : ((ArrayProperty) property).getMaxItems();
Object[] objectProperties = new Object[arrayLength]; |
Any update on this issue? |
I deleted maxItems from the spec if it was equal to Integer.MAX_VALUE. it's not a useful constraint in that case, neither to the generated code or any code relying on the spec to validate requests. |
I think the array length should be computed as a value between minItems and maxItems as close as possible from a magic number (2). |
Any update to this ? |
@robert-mygind you can remove or reduce the number of |
it's possible to exclude the example generator? |
swagger-jersey2-jaxrs generated spec may contain maxItem = 2147483647. Semantically this means there is no upper limit. Treating this as if the property was not present at all
I removed "maximum" : 10000000 and also "maxItems" : 2147483647 so now it works. |
ref #6394 - limit to 10 examples for array types
fixed in #9553 |
ref #6394 - limit to 10 examples for array types
Description
When running codegen I get an OutOfMemoryError
Exception in thread "main" java.lang.OutOfMemoryError: Requested array size exceeds VM limit
at io.swagger.codegen.examples.ExampleGenerator.resolvePropertyToExample(ExampleGenerator.java:160)
at io.swagger.codegen.examples.ExampleGenerator.resolveModelToExample(ExampleGenerator.java:251)
at io.swagger.codegen.examples.ExampleGenerator.resolvePropertyToExample(ExampleGenerator.java:210)
at io.swagger.codegen.examples.ExampleGenerator.resolvePropertyToExample(ExampleGenerator.java:161)
at io.swagger.codegen.examples.ExampleGenerator.generate(ExampleGenerator.java:49)
at io.swagger.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:2195)
at io.swagger.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:864)
at io.swagger.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:791)
at io.swagger.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:418)
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:730)
at io.swagger.codegen.cmd.Generate.run(Generate.java:285)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Swagger-codegen version
Just checkout from github and build
Swagger declaration file content or url
https://api.reepay.com/swagger.json
Command line used for generation
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i https://api.reepay.com/swagger.json -l php -o ~/Projects/reepay-php
Operation system and Java
OS X 10.11.6
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
The text was updated successfully, but these errors were encountered: