-
Type: Improvement
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Dev Exp
-
Fully Compatible
When using Ruby driver to manage the server deployment, there is often a need to create a client for a particular operation. Currently this requires a begin-ensure block to close the client:
client = Mongo::Client.new(...)
begin
client.database.command(ismaster: 1)
ensure
client.close
end
Instead it would be convenient to have the constructor yield to the provided block and close the client, so that the application code looked like this:
Mongo::Client.new(...) do |client| client.database.command(ismaster: 1) end
The constructor already yields self if a block is given, but does not close the client resulting in the client leak if the application actually used the pattern given above. Also this usage is not documented in https://docs.mongodb.com/ruby-driver/current/quick-start/ (which is additionally entirely silent on the need to close the client).
- is related to
-
RUBY-2288 Verify encryption client is closed when Client constructor block form is used
- Closed