Closed
Description
Version 1.0.68 introduces a memory leak.
When called repeatedly, we see the JSON Schema validator consumes all available memory, until it crashes with java.lang.OutOfMemoryError: Java heap space
The following script demonstrates it (uses Ammonite on JDK 17, Scala 2.13).
Run the script after setting JAVA_OPTS=-Xmx256M
This assumes you're parsing some fairly large JSON files (500kbyte in my case), and the JSON Schema is of some complexity. I assume you have some examples around like this to use.
Note that if you revert the version back to 1.0.67, the script runs successfully.
#!/usr/bin/env amm
interp.load.ivy("com.fasterxml.jackson.core" % "jackson-databind" % "2.13.2.1")
interp.load.ivy("com.networknt" % "json-schema-validator" % "1.0.68")
@
import java.nio.file.{Files, Path}
import com.fasterxml.jackson.databind.{JsonNode, ObjectMapper}
import com.networknt.schema.{JsonSchema, JsonSchemaFactory, SpecVersion}
val bigFile = Files.readString(Path.of("big-json-file.json"))
// In Scala, an object is similar to Java static classes, I think?
object JsonSchemaCheck {
private val jsonSchemaContent = Files.readString(Path.of("schema.json"))
private val validator = getJsonSchema(jsonSchemaContent)
private def getJson(content: String): JsonNode = {
val mapper = new ObjectMapper
mapper.readTree(content)
}
private def getJsonSchema(schema: String): JsonSchema = {
val factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)
factory.getSchema(schema)
}
def check(rawDoc: String) = {
val json = getJson(rawDoc)
validator.validate(json)
}
}
@main
def main(): Unit = {
Range(1,500).foreach { i =>
println(i)
JsonSchemaCheck.check(bigFile)
}
println("Done")
}
Metadata
Metadata
Assignees
Labels
No labels