Fix regression in CommandOperationHelper
The command creator can fail, and so it must be in a try block as well
to ensure the connection is released.
@@ -194,8 +194,9 @@ final class CommandOperationHelper {
final CommandCreator commandCreator, final Decoder<D> decoder,
final CommandReadTransformer<D, T> transformer, final boolean retryReads,
final Connection connection) {
- BsonDocument command = commandCreator.create(source.getServerDescription(), connection.getDescription());
MongoException exception;
+ try {
+ BsonDocument command = commandCreator.create(source.getServerDescription(), connection.getDescription());
try {
return executeCommand(database, command, decoder, source, connection, binding.getReadPreference(), transformer,
binding.getSessionContext(), binding.getServerApi());
@@ -208,7 +209,9 @@ final class CommandOperationHelper {
}
throw exception;
}
- } finally {
+ }
+ }
+ finally {
connection.release();
}
