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

SIGINT causes client to became unusable

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 12_01_17
    • Affects Version/s: bson-3.1.0, 2.1.0
    • Component/s: BSON, Public API
    • None
    • Environment:
      Mac OS X, ruby-2.2.3p173

      Sending a SIGINT while iterating over a cursor renders the Mongo::Client unusable since every subsequent operations throw an error.

      Unable to find source-code formatter for language: example.sh. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      jasoares@jasoares-mbp:~/work/projects/ruby_mongo_driver[term_signal_bug]$ rails c
      Loading development environment (Rails 4.1.11)
      # Initialize client
      [1] pry(main)> mc = Mongo::Client.new(['127.0.0.1:27017'], database: 'replicate_interruption_error')
      D, [2015-08-19T09:43:26.102296 #33495] DEBUG -- : MONGODB | Adding 127.0.0.1:27017 to the cluster. | runtime: 0.0284ms
      D, [2015-08-19T09:43:26.104635 #33495] DEBUG -- : MONGODB | Mongos 127.0.0.1:27017 discovered. | runtime: 0.0050ms
      # Populate sample collection with 500,000 documents
      => #<Mongo::Client:0x70208433641700 cluster=127.0.0.1:27017>
      [2] pry(main)> 10.times do |i|
      [2] pry(main)*   50.times do |j|
      [2] pry(main)*     inserts = 1_000.times.map do |k|
      [2] pry(main)*       { insert_one: { i: i, j: j, k: k, l: i * j * k, m: i + j + k } }
      [2] pry(main)*     end
      [2] pry(main)*     mc.database['items'].bulk_write(inserts, ordered: false)
      [2] pry(main)*   end
      [2] pry(main)* end
      => 10
      # Iterate over the collection
      [3] pry(main)> mc.database['items'].find.each { |dp, idx| "do nothing" }
      D, [2015-08-19T09:46:49.283045 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.find | STARTED | {:filter=>{:$query=>{}}, :project=>nil, :skip=>nil, :limit=>nil, :flags=>[]}
      D, [2015-08-19T09:46:49.289430 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.find | SUCCEEDED | 0.006415s
      D, [2015-08-19T09:46:49.289641 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.getmore | STARTED | {:cursor_id=>648716191431981301, :number_to_return=>0}
      D, [2015-08-19T09:46:51.099119 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.getmore | SUCCEEDED | 1.80946s
      D, [2015-08-19T09:46:51.116254 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.getmore | STARTED | {:cursor_id=>648716191431981301, :number_to_return=>0}
      D, [2015-08-19T09:46:52.435024 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.getmore | SUCCEEDED | 1.318786s
      D, [2015-08-19T09:46:52.460065 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.getmore | STARTED | {:cursor_id=>648716191431981301, :number_to_return=>0}
      # Interrupt by pressing control-c
      ^CD, [2015-08-19T09:46:52.899130 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.getmore | FAILED |  | 0.439064s
      Interrupt: 
      from /Users/jasoares/.rvm/gems/ruby-2.2.3/gems/mongo-2.1.0.beta/lib/mongo/socket.rb:91:in `gets'
      # From now on all operations return an error on BSON::Registry
      [4] pry(main)> mc.database['items'].find.to_a
      D, [2015-08-19T09:48:03.880668 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.find | STARTED | {:filter=>{:$query=>{}}, :project=>nil, :skip=>nil, :limit=>nil, :flags=>[]}
      D, [2015-08-19T09:48:04.812504 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.find | FAILED | key not found: "0" | 0.931848s
      KeyError: key not found: "0"
      from /Users/jasoares/.rvm/gems/ruby-2.2.3/gems/bson-3.1.0/lib/bson/registry.rb:43:in `fetch'
      [5] pry(main)> mc.database['items'].count
      D, [2015-08-19T09:48:17.339650 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.count | STARTED | {:count=>"items", :query=>{}}
      D, [2015-08-19T09:48:17.339947 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.count | FAILED | key not found: "\xD1" | 0.000314s
      KeyError: key not found: "\xD1"
      from /Users/jasoares/.rvm/gems/ruby-2.2.3/gems/bson-3.1.0/lib/bson/registry.rb:43:in `fetch'
      # Initialize a new cursor
      [6] pry(main)> mc = Mongo::Client.new(['127.0.0.1:27017'], database: 'replicate_interruption_error')
      D, [2015-08-19T09:58:51.182135 #33495] DEBUG -- : MONGODB | Adding 127.0.0.1:27017 to the cluster. | runtime: 0.0188ms
      D, [2015-08-19T09:58:51.183841 #33495] DEBUG -- : MONGODB | Mongos 127.0.0.1:27017 discovered. | runtime: 0.0098ms
      => #<Mongo::Client:0x70208333464260 cluster=127.0.0.1:27017>
      # It now works again
      [7] pry(main)> mc.database['items'].count
      D, [2015-08-19T09:58:53.565498 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.count | STARTED | {:count=>"items", :query=>{}}
      D, [2015-08-19T09:58:53.567157 #33495] DEBUG -- : MONGODB | 127.0.0.1:27017 | replicate_interruption_error.count | SUCCEEDED | 0.001658s
      => 500000
      

            Assignee:
            durran.jordan@mongodb.com Durran Jordan
            Reporter:
            jasoares João Soares
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: