debezium/dbz

MongoDbAuthProvider and MongoDbClientFactory lack close() lifecycle for resource cleanup

Open

#1,736 opened on Mar 23, 2026

View on GitHub
 (4 comments) (0 reactions) (1 assignee)HTML (6 forks)auto 404
component/mongodb-connectorgood first issuetype/task

Repository metrics

Stars
 (3 stars)
PR merge metrics
 (PR metrics pending)

Description

Feature request

Description

The MongoDbAuthProvider and MongoDbClientFactory interfaces have no close() method, so implementations that hold closeable resources (e.g. AWS STS clients, HTTP connection pools) have no way to release them when the connector task stops.

Currently, MongoDbConnectorTask.doStop() closes the schema but does not close the MongoDbConnectionContext, which holds the MongoDbClientFactory, which in turn holds the MongoDbAuthProvider. Any resources acquired during init() are never explicitly released.

For the default DefaultMongoDbAuthProvider this is harmless (it holds no closeable resources). However, custom MongoDbAuthProvider implementations — such as those using AWS IAM authentication with STS clients — would benefit from a proper cleanup path.

Proposed change

  1. Add default void close() {} to MongoDbAuthProvider interface
  2. Add default void close() {} to MongoDbClientFactory interface
  3. Override close() in DefaultMongoDbClientFactory to delegate to authProvider.close()
  4. Add close() to MongoDbConnectionContext to delegate to clientFactory.close()
  5. Call connectionContext.close() in MongoDbConnectorTask.doStop()

All default implementations are no-op, so this is fully backward compatible. Custom auth providers can override close() to release their resources.

Affected files

  • MongoDbAuthProvider.java
  • MongoDbClientFactory.java
  • DefaultMongoDbClientFactory.java
  • MongoDbConnectionContext.java
  • MongoDbConnectorTask.java

Contributor guide