Jiabao-Sun opened a new pull request, #86: URL: https://github.com/apache/flink-connector-mongodb/pull/86
## Description Since FLINK-38180, Flink 2.2 treats exceptions thrown during the cleanup of an already failed task as fatal, potentially terminating the entire TaskManager. Currently, MongoWriter.close() attempts to flush any remaining buffered records to MongoDB and propagates exceptions if the write fails. When a task has already failed due to a MongoDB write error (e.g., duplicate key, document validation failure, or server unavailability), the subsequent flush during close() may encounter the same error again. With Flink 2.2, this cleanup exception can cause the TaskManager to terminate instead of allowing the task failure to be handled through the normal recovery mechanism. This introduces a behavioral regression compared to Flink 1.19/1.20. Although no released version is currently affected, the issue needs to be addressed before the MongoDB connector's first Flink 2.x release. ## Expected Behavior MongoWriter.close() should handle failures during its final flush without propagating exceptions that could terminate the TaskManager. Such failures should be logged at ERROR level to ensure they remain visible for diagnostics. The behavior should also account for the configured delivery guarantee: - AT_LEAST_ONCE: Records are flushed during checkpointing and normal end-of-input processing. Records remaining after a failed or cancelled task can be replayed from the last successful checkpoint. - NONE: The final flush during close() may be the only attempt to write the remaining buffered records, particularly when stopping with a savepoint without draining. Suppressing an exception in this case may result in record loss, which must be clearly documented and logged. ## Brief change log Update MongoWriter.close() to catch and log MongoDB write exceptions without rethrowing them during cleanup. Document the implications for different delivery guarantees. Add an integration test in MongoWriterITCase that triggers a MongoDB write failure and verifies that close() returns normally without propagating the exception. Add a release note describing the change in cleanup failure handling. ## Impact Exceptions encountered while flushing buffered records during MongoWriter.close() are now logged instead of being propagated. For sinks configured with DeliveryGuarantee.NONE, a failed final flush may result in the loss of buffered records. ## Verifying this change CI passes in Flink 2.2.x -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
