{"record":{"id":"62407ba0e1f594b5","repo":"apache/seatunnel","slug":"failed-to-read-amazondocumentdb-data-from-database","errorCode":null,"errorMessage":"Failed to read AmazonDocumentDB data from database [%s], collection [%s]","messagePattern":"Failed to read AmazonDocumentDB data from database \\[(.+?)\\], collection \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/source/AmazonDocumentDBSourceReader.java","lineNumber":191,"sourceCode":"\n    BsonDocument fetchNextDocument(AmazonDocumentDBSourceSplit split) {\n        try {\n            if (cursor == null) {\n                FindIterable<BsonDocument> findIterable =\n                        collection.find(BsonDocument.parse(split.getMatchQuery()));\n                if (split.getProjection() != null) {\n                    findIterable.projection(BsonDocument.parse(split.getProjection()));\n                }\n                cursor = findIterable.batchSize(config.getFetchSize()).iterator();\n            }\n            if (cursor.hasNext()) {\n                return cursor.next();\n            }\n            closeCursor();\n            return null;\n        } catch (Exception e) {\n            closeCursor();\n            throw new IllegalStateException(\n                    String.format(\n                            \"Failed to read AmazonDocumentDB data from database [%s], collection [%s]\",\n                            config.getDatabase(), config.getCollection()),\n                    e);\n        }\n    }\n\n    private void closeCursor() {\n        if (cursor != null) {\n            cursor.close();\n            cursor = null;\n        }\n    }\n\n    private void finishCurrentSplit() {\n        LOG.info(\"AmazonDocumentDB reader [{}] finished source scan\", context.getIndexOfSubtask());\n        currentSplit = null;\n    }","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/source/AmazonDocumentDBSourceReader.java#L173-L209","documentation":"AmazonDocumentDBSourceReader.fetchNextDocument iterates the MongoDB cursor to fetch the next BsonDocument. On any exception during cursor.next() or the underlying fetch, it closes the cursor and rethrows as IllegalStateException naming the database and collection, so the reader fails rather than returning corrupted data.","triggerScenarios":"Cursor.next() throws (network drop to DocumentDB, cursor timed out / cursor id not found, replica-set state change, query killed server-side) while polling the next batch.","commonSituations":"Long-running read interrupted by DocumentDB idle-cursor timeout; network blip between the SeaTunnel worker and DocumentDB; failover of the DocumentDB primary during the scan; too-large batch causing memory/timeout pressure.","solutions":["Retry the job/reader; enable retryable reads on the MongoDB client (retryReads=true).","Tune cursor behavior: use smaller batch size or add an index on the filter/sort so cursors complete faster and avoid server-side timeout.","Check DocumentDB cluster health and network stability between workers and the cluster.","Inspect the cause chain for the driver error (MongoCursorNotFoundException, MongoTimeoutException) and address that root cause."],"exampleFix":"// before\nmongodb://host:27017\n// after: enable retryable reads and tighter timeouts\nmongodb://host:27017/?retryReads=true&maxIdleTimeMS=120000","handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { doc = reader.fetchNextDocument(); } catch (IllegalStateException e) { if (isTransient(e.getCause())) { restartReaderWithBackoff(); } else { throw e; } }","preventionTips":["Enable retryReads=true and sane socket/connect timeouts on the connection string.","Keep cursors short-lived; avoid full-collection scans without indexes; set appropriate maxIdleTimeMS.","Monitor DocumentDB failovers and network stability; design readers to be restartable (checkpointing)."],"tags":["java","documentdb","cursor","network"],"backgroundTag":"database-query-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}