jsondb-core
jsondb-core copied to clipboard
Failed to acquire lock for collection file ClosedChannelException
If you try to upsert a large collection that contains new and updated items the operation will fail.
Failed to acquire lock for collection file X.json
java.nio.channels.ClosedChannelException: null
at java.base/sun.nio.ch.FileChannelImpl.ensureOpen(FileChannelImpl.java:160) ~[?:?]
at java.base/sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:1463) ~[?:?]
at java.base/java.nio.channels.FileChannel.lock(FileChannel.java:1240) ~[?:?]
at io.jsondb.io.JsonWriter.acquireLock(JsonWriter.java:101) ~[jsondb-core-1.0.115-j11.jar:?]
at io.jsondb.io.JsonWriter.updateInJsonFile(JsonWriter.java:601) ~[jsondb-core-1.0.115-j11.jar:?]
at io.jsondb.JsonDBTemplate.upsert(JsonDBTemplate.java:1257) ~[jsondb-core-1.0.115-j11.jar:?]
at io.jsondb.JsonDBTemplate.upsert(JsonDBTemplate.java:1194) ~[jsondb-core-1.0.115-j11.jar:?]
After the items get appended, the file channel will get closed, causing the update to fail since its unable to obtain the file lock. https://github.com/Jsondb/jsondb-core/blob/12b2c72af8c52beb7fce34ef5ef01e59a74432b6/src/main/java/io/jsondb/JsonDBTemplate.java#L1257-L1268
https://github.com/Jsondb/jsondb-core/blob/12b2c72af8c52beb7fce34ef5ef01e59a74432b6/src/main/java/io/jsondb/io/JsonWriter.java#L114-L132
https://github.com/Jsondb/jsondb-core/blob/12b2c72af8c52beb7fce34ef5ef01e59a74432b6/src/main/java/io/jsondb/io/JsonWriter.java#L99-L112