Details
-
Improvement
-
Status: Closed
-
Minor - P4
-
Resolution: Fixed
-
None
-
Fully Compatible
Description
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).
Attachments
Issue Links
- is related to
-
RUBY-2288 Verify encryption client is closed when Client constructor block form is used
-
- Closed
-