apache/seatunnel · error · IllegalStateException
Failed to read AmazonDocumentDB data from database [%s], col
Error message
Failed to read AmazonDocumentDB data from database [%s], collection [%s]
What it means
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.
Source
Thrown at seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/source/AmazonDocumentDBSourceReader.java:191
BsonDocument fetchNextDocument(AmazonDocumentDBSourceSplit split) {
try {
if (cursor == null) {
FindIterable<BsonDocument> findIterable =
collection.find(BsonDocument.parse(split.getMatchQuery()));
if (split.getProjection() != null) {
findIterable.projection(BsonDocument.parse(split.getProjection()));
}
cursor = findIterable.batchSize(config.getFetchSize()).iterator();
}
if (cursor.hasNext()) {
return cursor.next();
}
closeCursor();
return null;
} catch (Exception e) {
closeCursor();
throw new IllegalStateException(
String.format(
"Failed to read AmazonDocumentDB data from database [%s], collection [%s]",
config.getDatabase(), config.getCollection()),
e);
}
}
private void closeCursor() {
if (cursor != null) {
cursor.close();
cursor = null;
}
}
private void finishCurrentSplit() {
LOG.info("AmazonDocumentDB reader [{}] finished source scan", context.getIndexOfSubtask());
currentSplit = null;
}View on GitHub (pinned to cf67b549a7)
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.
Example fix
// before mongodb://host:27017 // after: enable retryable reads and tighter timeouts mongodb://host:27017/?retryReads=true&maxIdleTimeMS=120000
Defensive patterns
Strategy: retry
Validate before calling
null
Type guard
null
Try / catch
try { doc = reader.fetchNextDocument(); } catch (IllegalStateException e) { if (isTransient(e.getCause())) { restartReaderWithBackoff(); } else { throw e; } } Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- Decimal precision %d exceeds configured precision %d
- Value is not a BSON date or timestamp
- Failed to open AmazonDocumentDB source reader for database [
- Failed to fetch metadata from Gravitino for metadata: %s
- fail get tableSchema:
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/62407ba0e1f594b5.
Report an issue: GitHub.