mperham / connection_pool

Generic connection pooling for Ruby
MIT License
1.63k stars 143 forks source link

Inaccurate proxy behavior when a hash with String and Symbol keys is passed #148

Closed qnighy closed 3 years ago

qnighy commented 3 years ago

The following code fails, starting from connection_pool 2.2.4 (https://github.com/mperham/connection_pool/pull/143).

require 'connection_pool'

class Logger
  def post(table, map)
    $stderr.puts "Wrote to #{table}: #{map.inspect}"
  end
end

logger = ConnectionPool::Wrapper.new { Logger.new }

logger.post('log', { user_id: 1, 'count' => 2 })

2.2.3:

$ ruby repro.rb
Wrote to log: {:user_id=>1, "count"=>2}

2.2.4 + Ruby 2.7:

$ ruby repro.rb
Traceback (most recent call last):
    9: from repro.rb:11:in `<main>'
    8: from /Users/qnighy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/connection_pool-2.2.4/lib/connection_pool/wrapper.rb:37:in `method_missing'
    7: from /Users/qnighy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/connection_pool-2.2.4/lib/connection_pool/wrapper.rb:14:in `with'
    6: from /Users/qnighy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/connection_pool-2.2.4/lib/connection_pool.rb:59:in `with'
    5: from /Users/qnighy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/connection_pool-2.2.4/lib/connection_pool.rb:59:in `handle_interrupt'
    4: from /Users/qnighy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/connection_pool-2.2.4/lib/connection_pool.rb:62:in `block in with'
    3: from /Users/qnighy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/connection_pool-2.2.4/lib/connection_pool.rb:62:in `handle_interrupt'
    2: from /Users/qnighy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/connection_pool-2.2.4/lib/connection_pool.rb:63:in `block (2 levels) in with'
    1: from /Users/qnighy/.rbenv/versions/2.7.2/lib/ruby/gems/2.7.0/gems/connection_pool-2.2.4/lib/connection_pool/wrapper.rb:38:in `block in method_missing'
repro2.rb:4:in `post': unknown keyword: :user_id (ArgumentError)

I wish it were an edge case, but unfortunately we found it in our production code.