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

session_pool : `synchronize': can't be called from trap context (ThreadError)

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      I see the following error randomly when running a large N+1 query job from the Rails console.

      For example, suppose I have 100,000 Users, and each User has 1000 Bananas, the following Mongoid code would trigger it randomly:

       

      User.each do |u|
        u.bananas.to_a
      end
      

       

       Note that it is not dependent on the model class.

      /opt/app/vendor/bundle/ruby/3.1.0/bundler/gems/bson-ruby-acf1be4b9c62/lib/bson/registry.rb:44: warning: Exception in finalizer #<Proc:0x00007fdae0aa6ff0 /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/cursor.rb:113>
      /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/session/session_pool.rb:102:in `synchronize': can't be called from trap context (ThreadError)
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/session/session_pool.rb:102:in `checkin'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/session.rb:328:in `end_session'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/cursor.rb:115:in `block in finalize'
              from /opt/app/vendor/bundle/ruby/3.1.0/bundler/gems/bson-ruby-acf1be4b9c62/lib/bson/registry.rb:44:in `get'
              from /opt/app/vendor/bundle/ruby/3.1.0/bundler/gems/bson-ruby-acf1be4b9c62/lib/bson/hash.rb:110:in `get_hash'
              from /opt/app/vendor/bundle/ruby/3.1.0/bundler/gems/bson-ruby-acf1be4b9c62/lib/bson/hash.rb:110:in `from_bson'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/dbref.rb:113:in `from_bson'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/protocol/serializers.rb:285:in `deserialize'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/protocol/serializers.rb:222:in `deserialize'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/protocol/message.rb:456:in `deserialize_field'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/protocol/compressed.rb:103:in `block in maybe_inflate'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/protocol/compressed.rb:99:in `each'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/protocol/compressed.rb:99:in `maybe_inflate'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/protocol/message.rb:290:in `deserialize'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/server/connection_base.rb:186:in `block (2 levels) in deliver'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/server/connection_common.rb:146:in `add_server_diagnostics'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/server/connection_base.rb:183:in `block in deliver'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/server/connection_common.rb:194:in `ensure_connected'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/server/connection_base.rb:172:in `deliver'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/server/connection.rb:325:in `block in deliver'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/server/connection.rb:331:in `handle_errors'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/server/connection.rb:324:in `deliver'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/server/connection_base.rb:161:in `dispatch'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/executable.rb:84:in `dispatch_message'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/executable.rb:77:in `get_result'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/executable.rb:33:in `block (3 levels) in do_execute'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/response_handling.rb:107:in `add_server_diagnostics'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/executable.rb:32:in `block (2 levels) in do_execute'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/response_handling.rb:54:in `add_error_labels'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/executable.rb:31:in `block in do_execute'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/response_handling.rb:93:in `unpin_maybe'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/executable.rb:30:in `do_execute'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/executable.rb:65:in `execute'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/polymorphic_operation.rb:37:in `block in execute'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/server/connection_pool.rb:639:in `with_connection'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/server.rb:448:in `with_connection'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/operation/shared/polymorphic_operation.rb:35:in `execute'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/cursor.rb:473:in `execute_operation'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/cursor.rb:365:in `get_more'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/cursor.rb:220:in `try_next'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/cursor.rb:168:in `block in each'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/cursor.rb:167:in `loop'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/cursor.rb:167:in `each'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongo-2.17.1/lib/mongo/collection/view/iterable.rb:85:in `each'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongoid-7.5.1/lib/mongoid/contextual/mongo.rb:745:in `map'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongoid-7.5.1/lib/mongoid/contextual/mongo.rb:745:in `documents_for_iteration'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/mongoid-7.5.1/lib/mongoid/contextual/mongo.rb:152:in `each'
              from /usr/local/lib/ruby/3.1.0/forwardable.rb:238:in `each'
              from (irb):16:in `<main>'
              from /usr/local/lib/ruby/3.1.0/irb/workspace.rb:119:in `eval'
              from /usr/local/lib/ruby/3.1.0/irb/workspace.rb:119:in `evaluate'
              from /usr/local/lib/ruby/3.1.0/irb/context.rb:476:in `evaluate'
              from /usr/local/lib/ruby/3.1.0/irb.rb:577:in `block (2 levels) in eval_input'
              from /usr/local/lib/ruby/3.1.0/irb.rb:770:in `signal_status'
              from /usr/local/lib/ruby/3.1.0/irb.rb:558:in `block in eval_input'
              from /usr/local/lib/ruby/3.1.0/irb/ruby-lex.rb:268:in `block (2 levels) in each_top_level_statement'
              from /usr/local/lib/ruby/3.1.0/irb/ruby-lex.rb:250:in `loop'
              from /usr/local/lib/ruby/3.1.0/irb/ruby-lex.rb:250:in `block in each_top_level_statement'
              from /usr/local/lib/ruby/3.1.0/irb/ruby-lex.rb:249:in `catch'
              from /usr/local/lib/ruby/3.1.0/irb/ruby-lex.rb:249:in `each_top_level_statement'
              from /usr/local/lib/ruby/3.1.0/irb.rb:557:in `eval_input'
              from /usr/local/lib/ruby/3.1.0/irb.rb:491:in `block in run'
              from /usr/local/lib/ruby/3.1.0/irb.rb:490:in `catch'
              from /usr/local/lib/ruby/3.1.0/irb.rb:490:in `run'
              from /usr/local/lib/ruby/3.1.0/irb.rb:419:in `start'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/console/console_command.rb:70:in `start'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/console/console_command.rb:19:in `start'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands/console/console_command.rb:102:in `perform'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/command/base.rb:87:in `perform'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/command.rb:48:in `invoke'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/railties-7.0.3.1/lib/rails/commands.rb:18:in `<main>'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
              from /opt/app/vendor/bundle/ruby/3.1.0/gems/bootsnap-1.12.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
              from bin/rails:4:in `<main>'
      

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            shields@tablecheck.com Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: