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

Socket is nil error when primary in replicaset is shut down (NoMethodError: undefined method `write' for nil:NilClass)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.5, 2.2.6
    • Affects Version/s: 2.2.4
    • Component/s: Replica Set
    • Environment:
      Ubuntu, 3 node replicaset, Ruby 2.2.x, mongoid5.1

      This issue happens when the primary node in a Replicaset is shut down (pull the plug, not shutdown -h).

      The driver is configured with a read mode of `primary`.

      The driver attempts to write on a socket that is `nil`, this is not caught by the `handle_errors` method on the socket so it will raise an error as opposed to retrying the query.

      Here is a stacktrace:

      ```
      NoMethodError: undefined method `write' for nil:NilClass
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/socket.rb:157:in `block in write'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/socket.rb:191:in `handle_errors'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/socket.rb:157:in `write'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/server/connection.rb:179:in `block in write'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/server/connectable.rb:91:in `ensure_connected'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/server/connection.rb:179:in `write'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/server/connection.rb:157:in `deliver'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/server/connection.rb:104:in `block in dispatch'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/monitoring/publishable.rb:47:in `publish_command'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/server/connection.rb:103:in `dispatch'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/operation/executable.rb:36:in `block in execute'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/server/connection_pool.rb:108:in `with_connection'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/server/context.rb:63:in `with_connection'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/operation/executable.rb:34:in `execute'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/collection/view/iterable.rb:79:in `send_initial_query'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/collection/view/iterable.rb:41:in `block in each'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/retryable.rb:51:in `call'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/retryable.rb:51:in `read_with_retry'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongo-2.2.4/lib/mongo/collection/view/iterable.rb:39:in `each'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongoid-5.1.1/lib/mongoid/query_cache.rb:207:in `each'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongoid-5.1.1/lib/mongoid/contextual/mongo.rb:252:in `first'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongoid-5.1.1/lib/mongoid/contextual/mongo.rb:252:in `find_first'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongoid-5.1.1/lib/mongoid/contextual.rb:20:in `find_first'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongoid-5.1.1/lib/mongoid/findable.rb:114:in `find_by'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongoid-5.1.1/lib/mongoid/criteria.rb:497:in `block in method_missing'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongoid-5.1.1/lib/mongoid/scopable.rb:230:in `with_scope'
      my_app/vendor/bundle/ruby/2.2.0/gems/mongoid-5.1.1/lib/mongoid/criteria.rb:496:in `method_missing'
      my_app/app/models/site.rb:83:in `for_worker'
      ```

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            robert@appsignal.com Robert Beekman
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: