Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1227

Setting min_pool_size and not max_pool_size gives unhelpful error message

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5.0
    • Affects Version/s: 2.4.3
    • Component/s: None
    • Labels:
      None

      Because of the changes introduced in RUBY-1201, there is now a slight glitch: if you try to create a MongoClient with an explicit nil value in the min_pool_size, like this:

      require 'mongo'
      Mongo::Client.new(mongo_uri, min_pool_size: nil, max_pool_size: nil)

      ...you will get an error like this:

      NoMethodError: undefined method `<=' for nil:NilClass

      /Users/plundberg/.rvm/gems/ruby-2.4.1/gems/mongo-2.4.3/lib/mongo/client.rb:414:in `validate_max_min_pool_size!'
      /Users/plundberg/.rvm/gems/ruby-2.4.1/gems/mongo-2.4.3/lib/mongo/client.rb:403:in `block in validate_options!'
      /Users/plundberg/.rvm/gems/ruby-2.4.1/gems/mongo-2.4.3/lib/mongo/client.rb:401:in `select'
      /Users/plundberg/.rvm/gems/ruby-2.4.1/gems/mongo-2.4.3/lib/mongo/client.rb:401:in `validate_options!'
      /Users/plundberg/.rvm/gems/ruby-2.4.1/gems/mongo-2.4.3/lib/mongo/client.rb:233:in `initialize'
      ./lib/ecraft/mongo_library/mongo_mixin.rb:55:in `new'

      I think this is not so friendly to the users of the library, especially since this breaks compatibility with previous versions (the code above works fine on 2.4.1).

      Possible strategies for fixing it:

      • In client.rb, remove min_pool_size from the options hash if it is nil before performing the validation. Simple, doesn't break anything and will make the code again compatible with 2.4.1.
      • Detect that it's nil and raise a better error message. Also acceptable, but less compatible with users of 2.4.1.

      I would suggest going with the first approach. Emily, thanks for your instant feedback in the other issue. Let me know if you want me to fix it, I'll gladly submit a PR (it's a 5-minute fix), but if you want to fix it yourself, it's also completely fine.

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            perlundberg Per Lundberg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: