arangodb / arangodb-java-driver

The official ArangoDB Java driver.
Apache License 2.0
200 stars 93 forks source link

Synchronous streaming batched cursor throws exception when attempting to close after last batch is consumed #528

Closed philipp-birkl closed 6 months ago

philipp-birkl commented 7 months ago

An com.arangodb.ArangoDBException is thrown when trying to close a streaming batched cursor.

Such as

        try(ArangoCursor<Map> cursor = db.query("FOR el in collection RETURN el",
            Map.class,
            new AqlQueryOptions()
                .ttl(3600)
                .batchSize(2)
                .stream(true))) {

            while(cursor.hasNext()) {
                log.info("{}", cursor.next());
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

This code throws an error when closing the cursor after the try-with-resources block is finished.

com.arangodb.ArangoDBException: Response: 404, Error: 1600 - cursor not found
    at com.arangodb.ArangoDBException.of(ArangoDBException.java:137)
    at com.arangodb.ArangoDBException.of(ArangoDBException.java:111)
    at com.arangodb.ArangoDBException.of(ArangoDBException.java:107)
    at com.arangodb.internal.net.CommunicationProtocol.execute(CommunicationProtocol.java:43)
    at com.arangodb.internal.ArangoExecutorSync.execute(ArangoExecutorSync.java:55)
    at com.arangodb.internal.ArangoExecutorSync.execute(ArangoExecutorSync.java:43)
    at com.arangodb.internal.ArangoDatabaseImpl$1.close(ArangoDatabaseImpl.java:216)
    at com.arangodb.internal.cursor.ArangoCursorImpl.close(ArangoCursorImpl.java:60)
Product Version
Spring Boot 3.2.0
ArangoDB 3.11
Arango Java Driver 7.3.0
rashtao commented 6 months ago

Fix released in https://github.com/arangodb/arangodb-java-driver/releases/tag/v7.4.0