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

Multithreading issues when handling closed connections

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 1.3.1
    • Fix Version/s: 1.4.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      JRuby 1.6.2

      Description

      We see a few errors in the connection/reconnection logic in the Mongo Ruby driver. Since we're running JRuby, and have a few threads interacting with the Mongo driver, my guess is that it's multithreading issues. I've included three examples (I can add more as they happen again, these three have happened just in the past day), along with backtraces from the point where control leaves our application code. I've also elided the path to the gem, to make it easier to read.

      This one looks like it's trying to disconnect a connection that has already been disconnected:

      NoMethodError: undefined method `close' for nil:NilClass

      mongo-1.3.1/lib/mongo/util/pool.rb:131:in `checkout_existing_socket'
      mongo-1.3.1/lib/mongo/util/pool.rb:154:in `checkout'
      mongo-1.3.1/lib/mongo/util/pool.rb:152:in `checkout'
      org/jruby/RubyKernel.java:1419:in `loop'
      mongo-1.3.1/lib/mongo/util/pool.rb:145:in `checkout'
      mongo-1.3.1/lib/mongo/connection.rb:579:in `checkout_reader'
      mongo-1.3.1/lib/mongo/connection.rb:477:in `receive_message'
      mongo-1.3.1/lib/mongo/connection.rb:472:in `receive_message'
      mongo-1.3.1/lib/mongo/cursor.rb:407:in `send_initial_query'
      mongo-1.3.1/lib/mongo/connection.rb:609:in `instrument'
      mongo-1.3.1/lib/mongo/cursor.rb:406:in `send_initial_query'
      mongo-1.3.1/lib/mongo/cursor.rb:371:in `refresh'
      mongo-1.3.1/lib/mongo/cursor.rb:87:in `next_document'
      mongo-1.3.1/lib/mongo/cursor.rb:249:in `each'
      org/jruby/RubyEnumerable.java:401:in `to_a'
      mongo-1.3.1/lib/mongo/cursor.rb:267:in `to_a'

      This one seems to assume that @host and @port have been set already, when they haven't (we haven't accidentally forgot to give it the host and port, or set them to nil):

      Mongo::ConnectionFailure: Failed to connect to host and port : no implicit conversion from nil to integer

      mongo-1.3.1/lib/mongo/util/pool.rb:80:in `checkout_new_socket'
      mongo-1.3.1/lib/mongo/util/pool.rb:156:in `checkout'
      mongo-1.3.1/lib/mongo/util/pool.rb:152:in `checkout'
      org/jruby/RubyKernel.java:1419:in `loop'
      mongo-1.3.1/lib/mongo/util/pool.rb:145:in `checkout'
      mongo-1.3.1/lib/mongo/connection.rb:586:in `checkout_writer'
      mongo-1.3.1/lib/mongo/connection.rb:477:in `receive_message'
      mongo-1.3.1/lib/mongo/connection.rb:472:in `receive_message'
      mongo-1.3.1/lib/mongo/cursor.rb:407:in `send_initial_query'
      mongo-1.3.1/lib/mongo/connection.rb:609:in `instrument'
      mongo-1.3.1/lib/mongo/cursor.rb:406:in `send_initial_query'
      mongo-1.3.1/lib/mongo/cursor.rb:371:in `refresh'
      mongo-1.3.1/lib/mongo/cursor.rb:87:in `next_document'
      mongo-1.3.1/lib/mongo/db.rb:497:in `command'
      mongo-1.3.1/lib/mongo/connection.rb:571:in `max_bson_size'
      bson-1.3.1-java/lib/bson/bson_java.rb:25:in `update_max_bson_size'
      mongo-1.3.1/lib/mongo/connection.rb:516:in `connect'

      Here, @primary_pool hasn't been set yet:

      NoMethodError: undefined method `checkout' for nil:NilClass

      mongo-1.3.1/lib/mongo/connection.rb:586:in `checkout_writer'
      mongo-1.3.1/lib/mongo/connection.rb:477:in `receive_message'
      mongo-1.3.1/lib/mongo/connection.rb:472:in `receive_message'
      mongo-1.3.1/lib/mongo/cursor.rb:407:in `send_initial_query'
      mongo-1.3.1/lib/mongo/connection.rb:609:in `instrument'
      mongo-1.3.1/lib/mongo/cursor.rb:406:in `send_initial_query'
      mongo-1.3.1/lib/mongo/cursor.rb:371:in `refresh'
      mongo-1.3.1/lib/mongo/cursor.rb:87:in `next_document'
      mongo-1.3.1/lib/mongo/db.rb:497:in `command'
      mongo-1.3.1/lib/mongo/connection.rb:571:in `max_bson_size'
      bson-1.3.1-java/lib/bson/bson_java.rb:25:in `update_max_bson_size'
      mongo-1.3.1/lib/mongo/connection.rb:516:in `connect'

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: