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

insert_one id: undefined method [] for nil:NilClass

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.13.0
    • Component/s: Query
    • None
    • Environment:
      OpenStack instance running Gentoo
      Linux kernel 4.19.134
      Ruby v2.5.8p224
      Mongo Ruby driver 2.13.0

      I had two identical errors with Ruby Mongo 2.13.0 insert_one within `idable.rb` failing to find an 'id' field on a nil object; this occurred on two unique Ruby threads performing the same operation with different document contents (example inserted data below).

      Logs show the data that was inserted, and those documents do exist within the DB collection each containing an '_id' field, so the mongo connector crashed directly followig the insert. Both Ruby threads running these actions crashed and were restarted by a keepalive task.. Other threads running simultaneously with similar document insertions did not experience any issues.

      I have not seen this error happen before updating to 2.13.0, nor have I seen it occur again. No errors were noted on the MongoDB host that could explain what happened.

      /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/idable.rb:47:in `id': undefined method `[]' for nil:NilClass (NoMethodError)
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/idable.rb:51:in `has_id?'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/idable.rb:57:in `block in ensure_ids'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/idable.rb:56:in `collect'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/idable.rb:56:in `ensure_ids'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/idable.rb:24:in `documents'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/insert/op_msg.rb:45:in `message'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/executable.rb:68:in `build_message'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/sessions_supported.rb:225:in `build_message'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/executable.rb:61:in `dispatch_message'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/insert/op_msg.rb:35:in `get_result'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/executable.rb:29:in `block (3 levels) in do_execute'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/response_handling.rb:96:in `add_server_diagnostics'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/executable.rb:28:in `block (2 levels) in do_execute'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/response_handling.rb:43:in `add_error_labels'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/executable.rb:27:in `block in do_execute'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/response_handling.rb:82:in `unpin_maybe'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/executable.rb:26:in `do_execute'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/executable_no_validate.rb:25:in `execute'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/write.rb:49:in `block in execute'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/server/connection_pool.rb:590:in `with_connection'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/server.rb:425:in `with_connection'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/operation/shared/write.rb:39:in `execute'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/collection.rb:556:in `block (2 levels) in insert_one'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/retryable.rb:293:in `legacy_write_with_retry'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/retryable.rb:202:in `write_with_retry'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/collection.rb:545:in `block in insert_one'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/client.rb:1007:in `with_session'
              from /home/gentoo/.gem/ruby/2.5.0/gems/mongo-2.13.0/lib/mongo/collection.rb:539:in `insert_one'
      

      Data inserted from one of the threads:

      {
          "_id" : ObjectId("5f490a708739a23a69845250"),
          "id" : "0c556980-0dff-45dd-b9b3-36b08b68cb4d",
          "ref_id" : null,
          "cancel" : null,
          "instrument" : "https://api.robinhood.com/instruments/49335ec7-8b86-4021-b656-6e45c37da4ed/",
          "cumulative_quantity" : 4,
          "average_price" : 44.92,
          "fees" : "0.00",
          "state" : "filled",
          "type" : "limit",
          "side" : "buy",
          "time_in_force" : "gfd",
          "trigger" : "immediate",
          "price" : 44.92,
          "stop_price" : 0.0,
          "quantity" : 4,
          "reject_reason" : null,
          "created_at" : "2020-08-28T13:45:12.635710Z",
          "updated_at" : "2020-08-28T13:45:13.328872Z",
          "last_transaction_at" : "2020-08-28T13:45:12.856000Z",
          "executions" : [ 
              {
                  "price" : "44.92000000",
                  "quantity" : "4.00000000",
                  "settlement_date" : "2020-09-01",
                  "timestamp" : "2020-08-28T13:45:12.856000Z",
                  "id" : "17a57e15-4f40-45b0-a215-22d4014a5ee1"
              }
          ],
          "extended_hours" : true,
          "override_dtbp_checks" : false,
          "override_day_trade_checks" : false,
          "response_category" : null,
          "stop_triggered_at" : null,
          "last_trail_price" : null,
          "last_trail_price_updated_at" : null,
          "dollar_based_amount" : null,
          "total_notional" : {
              "amount" : "179.68",
              "currency_code" : "USD",
              "currency_id" : "1072fc76-1862-41ab-82c2-485837590762"
          },
          "executed_notional" : {
              "amount" : "179.68",
              "currency_code" : "USD",
              "currency_id" : "1072fc76-1862-41ab-82c2-485837590762"
          },
          "investment_schedule_id" : null,
          "symbol" : "VWO",
          "info" : {
              "b_id" : null,
              "pos_id" : ObjectId("5eeaf7708739a248c3d95145"),
              "inv_id" : ObjectId("5e3ad7da246746697d5d54c7"),
              "wl_id" : ObjectId("5e128cc00ecf9608187e08ac"),
              "pl_id" : ObjectId("5f4906f48739a23a6984523c"),
              "start" : null,
              "chart" : "15m",
              "attempts" : 1,
              "sim" : false,
              "realtime" : true,
              "time_placed" : ISODate("2020-08-28T13:45:11.862Z"),
              "timerange" : {
                  "start" : ISODate("2020-08-28T13:30:00.000Z"),
                  "end" : ISODate("2020-08-28T20:00:00.000Z")
              },
              "tracker" : [ 
                  {
                      "_id" : "VWO",
                      "count" : 7,
                      "date" : ISODate("2020-08-28T13:30:00.000Z"),
                      "sma" : 44.646,
                      "last" : 44.92,
                      "diff" : 0.2743
                  }, 
                  {
                      "_id" : "VWO",
                      "count" : 7,
                      "roc" : 0.717
                  }
              ],
              "pl_start" : ISODate("2020-08-28T13:30:28.998Z")
          }
      }
      

       

            Assignee:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Reporter:
            danheneise@me.com Dan Heneise
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: