Skip to content
  • zzak's avatar
    5f53cf96
    Reduce chances to hit mysql2 execute with prepared statements bug · 5f53cf96
    zzak authored
    By decreasing the amount of cycles performed in this test we can avoid
    whatever is causing this type of flake:
    
    ```
    /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:323:in `expire': Cannot expire connection, it is not currently leased. (ActiveRecord::ActiveRecordError)
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:572:in `block (3 levels) in checkin'
            from /home/zzak/code/rails/activesupport/lib/active_support/callbacks.rb:109:in `run_callbacks'
            from /home/zzak/code/rails/activesupport/lib/active_support/callbacks.rb:912:in `_run_checkin_callbacks'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `block (2 levels) in checkin'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `synchronize'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `mon_synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:568:in `block in checkin'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:567:in `checkin'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:384:in `release_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:415:in `ensure in with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:415:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:277:in `_update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:622:in `update_columns'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `block in decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:40:in `with_encryption_context'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:50:in `without_encryption'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:172:in `decrypt'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:22:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `_execute': Mysql2::Error: Mysql2::Error: `UPDATE `posts` SET `posts`.`title` = ?, `posts`.`body` = ? WHERE `posts`.`id` = ?` Bind parameter count (0) doesn't match number of arguments (3) (ActiveRecord::StatementInvalid)
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `block in execute'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `handle_interrupt'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:71:in `block in perform_query'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/share_lock.rb:186:in `yield_shares'
            from /home/zzak/code/rails/activesupport/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:70:in `perform_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:556:in `block (2 levels) in raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1011:in `block in with_raw_connection'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:983:in `with_raw_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:555:in `block in raw_execute'
            from /home/zzak/code/rails/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1129:in `log'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:554:in `raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:591:in `internal_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:173:in `exec_update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:208:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:27:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:278:in `block in _update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:412:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:277:in `_update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:622:in `update_columns'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `block in decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:40:in `with_encryption_context'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:50:in `without_encryption'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:172:in `decrypt'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:22:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `_execute': Mysql2::Error: `UPDATE `posts` SET `posts`.`title` = ?, `posts`.`body` = ? WHERE `posts`.`id` = ?` Bind parameter count (0) doesn't match number of arguments (3) (Mysql2::Error)
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `block in execute'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `handle_interrupt'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:71:in `block in perform_query'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/share_lock.rb:186:in `yield_shares'
            from /home/zzak/code/rails/activesupport/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:70:in `perform_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:556:in `block (2 levels) in raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1011:in `block in with_raw_connection'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:983:in `with_raw_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:555:in `block in raw_execute'
            from /home/zzak/code/rails/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1129:in `log'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:554:in `raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:591:in `internal_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:173:in `exec_update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:208:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:27:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:278:in `block in _update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:412:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:277:in `_update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:622:in `update_columns'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `block in decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:40:in `with_encryption_context'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:50:in `without_encryption'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:172:in `decrypt'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:22:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `_execute': Bind parameter count (0) doesn't match number of arguments (3) (Mysql2::Error)
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `block in execute'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `handle_interrupt'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:71:in `block in perform_query'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/share_lock.rb:186:in `yield_shares'
            from /home/zzak/code/rails/activesupport/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:70:in `perform_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:556:in `block (2 levels) in raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1011:in `block in with_raw_connection'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:983:in `with_raw_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:555:in `block in raw_execute'
            from /home/zzak/code/rails/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1129:in `log'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:554:in `raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:591:in `internal_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:173:in `exec_update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:208:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:27:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:278:in `block in _update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:412:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:277:in `_update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:622:in `update_columns'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `block in decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:40:in `with_encryption_context'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:50:in `without_encryption'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:172:in `decrypt'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:22:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    E
    
    Error:
    ActiveRecord::Encryption::ConcurrencyTest#test_models_can_be_encrypted_and_decrypted_in_different_threads_concurrently:
    ActiveRecord::StatementInvalid: Mysql2::Error: Mysql2::Error: `SELECT `posts`.* FROM `posts` WHERE `posts`.`type` = ? ORDER BY `posts`.`id` DESC LIMIT ?` Commands out of sync; you can't run this command now
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `_execute'
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `block in execute'
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `handle_interrupt'
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `execute'
        lib/active_record/connection_adapters/mysql2/database_statements.rb:71:in `block in perform_query'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/share_lock.rb:186:in `yield_shares'
        /home/zzak/code/rails/activesupport/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
        lib/active_record/connection_adapters/mysql2/database_statements.rb:70:in `perform_query'
        lib/active_record/connection_adapters/abstract/database_statements.rb:556:in `block (2 levels) in raw_execute'
        lib/active_record/connection_adapters/abstract_adapter.rb:1011:in `block in with_raw_connection'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
        lib/active_record/connection_adapters/abstract_adapter.rb:983:in `with_raw_connection'
        lib/active_record/connection_adapters/abstract/database_statements.rb:555:in `block in raw_execute'
        /home/zzak/code/rails/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
        lib/active_record/connection_adapters/abstract_adapter.rb:1129:in `log'
        lib/active_record/connection_adapters/abstract/database_statements.rb:554:in `raw_execute'
        lib/active_record/connection_adapters/abstract/database_statements.rb:591:in `internal_execute'
        lib/active_record/connection_adapters/abstract/database_statements.rb:547:in `internal_exec_query'
        lib/active_record/connection_adapters/abstract/database_statements.rb:693:in `select'
        lib/active_record/connection_adapters/abstract/database_statements.rb:73:in `select_all'
        lib/active_record/connection_adapters/abstract/query_cache.rb:251:in `select_all'
        lib/active_record/connection_adapters/mysql2/database_statements.rb:12:in `select_all'
        lib/active_record/querying.rb:68:in `_query_by_sql'
        lib/active_record/relation.rb:1449:in `block (2 levels) in exec_main_query'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:406:in `with_connection'
        lib/active_record/connection_handling.rb:310:in `with_connection'
        lib/active_record/relation.rb:1448:in `block in exec_main_query'
        lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
        lib/active_record/relation.rb:1432:in `exec_main_query'
        lib/active_record/relation.rb:1410:in `block in exec_queries'
        lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
        lib/active_record/relation.rb:1404:in `exec_queries'
        lib/active_record/relation.rb:1181:in `load'
        lib/active_record/relation.rb:343:in `records'
        lib/active_record/relation/delegation.rb:101:in `reverse'
        lib/active_record/relation/finder_methods.rb:208:in `last'
        lib/active_record/querying.rb:24:in `last'
        test/cases/encryption/concurrency_test.rb:17:in `thread_encrypting_and_decrypting'
        test/cases/encryption/concurrency_test.rb:12:in `block (2 levels) in <class:ConcurrencyTest>'
        test/cases/encryption/concurrency_test.rb:12:in `times'
        test/cases/encryption/concurrency_test.rb:12:in `each'
        test/cases/encryption/concurrency_test.rb:12:in `collect'
        test/cases/encryption/concurrency_test.rb:12:in `block in <class:ConcurrencyTest>'
    
    Error:
    ActiveRecord::Encryption::ConcurrencyTest#test_models_can_be_encrypted_and_decrypted_in_different_threads_concurrently:
    ActiveRecord::ActiveRecordError: Cannot expire connection, it is not currently leased.
        lib/active_record/connection_adapters/abstract_adapter.rb:323:in `expire'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:572:in `block (3 levels) in checkin'
        /home/zzak/code/rails/activesupport/lib/active_support/callbacks.rb:109:in `run_callbacks'
        /home/zzak/code/rails/activesupport/lib/active_support/callbacks.rb:912:in `_run_checkin_callbacks'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `block (2 levels) in checkin'
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `synchronize'
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `mon_synchronize'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:568:in `block in checkin'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:567:in `checkin'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:384:in `release_connection'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:415:in `ensure in with_connection'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:415:in `with_connection'
        lib/active_record/connection_handling.rb:310:in `with_connection'
        lib/active_record/persistence.rb:277:in `_update_record'
        lib/active_record/persistence.rb:622:in `update_columns'
        lib/active_record/encryption/encryptable_record.rb:197:in `block in decrypt_attributes'
        lib/active_record/encryption/contexts.rb:40:in `with_encryption_context'
        lib/active_record/encryption/contexts.rb:50:in `without_encryption'
        lib/active_record/encryption/encryptable_record.rb:197:in `decrypt_attributes'
        lib/active_record/encryption/encryptable_record.rb:172:in `decrypt'
        test/cases/encryption/concurrency_test.rb:22:in `block (2 levels) in thread_encrypting_and_decrypting'
        test/cases/encryption/concurrency_test.rb:20:in `each'
        test/cases/encryption/concurrency_test.rb:20:in `with_index'
        test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    
    /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:545:in `block (2 levels) in checkout': undefined method `verify!' for nil:NilClass (NoMethodError)
    
                  @pinned_connection.verify!
                                    ^^^^^^^^
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `synchronize'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `mon_synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:544:in `block in checkout'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:543:in `checkout'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:412:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1448:in `block in exec_main_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1432:in `exec_main_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1410:in `block in exec_queries'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1404:in `exec_queries'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1181:in `load'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:343:in `records'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:586:in `find_take'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:129:in `take'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:135:in `take!'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:118:in `find_by!'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:834:in `_find_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:749:in `block in reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1373:in `_scoping'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:548:in `scoping'
            from /home/zzak/code/rails/activerecord/lib/active_record/scoping/default.rb:51:in `unscoped'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:749:in `reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/attribute_methods/dirty.rb:64:in `reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/autosave_association.rb:241:in `reload'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/helper.rb:22:in `assert_encrypted_attribute'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:21:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:545:in `block (2 levels) in checkout': undefined method `verify!' for nil:NilClass (NoMethodError)
    
                  @pinned_connection.verify!
                                    ^^^^^^^^
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `synchronize'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `mon_synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:544:in `block in checkout'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:543:in `checkout'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:412:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1448:in `block in exec_main_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1432:in `exec_main_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1410:in `block in exec_queries'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1404:in `exec_queries'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1181:in `load'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:343:in `records'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:586:in `find_take'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:129:in `take'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:135:in `take!'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:118:in `find_by!'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:834:in `_find_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:749:in `block in reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1373:in `_scoping'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:548:in `scoping'
            from /home/zzak/code/rails/activerecord/lib/active_record/scoping/default.rb:51:in `unscoped'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:749:in `reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/attribute_methods/dirty.rb:64:in `reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/autosave_association.rb:241:in `reload'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/helper.rb:22:in `assert_encrypted_attribute'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:21:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    ```
    5f53cf96
    Reduce chances to hit mysql2 execute with prepared statements bug
    zzak authored
    By decreasing the amount of cycles performed in this test we can avoid
    whatever is causing this type of flake:
    
    ```
    /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:323:in `expire': Cannot expire connection, it is not currently leased. (ActiveRecord::ActiveRecordError)
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:572:in `block (3 levels) in checkin'
            from /home/zzak/code/rails/activesupport/lib/active_support/callbacks.rb:109:in `run_callbacks'
            from /home/zzak/code/rails/activesupport/lib/active_support/callbacks.rb:912:in `_run_checkin_callbacks'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `block (2 levels) in checkin'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `synchronize'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `mon_synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:568:in `block in checkin'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:567:in `checkin'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:384:in `release_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:415:in `ensure in with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:415:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:277:in `_update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:622:in `update_columns'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `block in decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:40:in `with_encryption_context'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:50:in `without_encryption'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:172:in `decrypt'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:22:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `_execute': Mysql2::Error: Mysql2::Error: `UPDATE `posts` SET `posts`.`title` = ?, `posts`.`body` = ? WHERE `posts`.`id` = ?` Bind parameter count (0) doesn't match number of arguments (3) (ActiveRecord::StatementInvalid)
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `block in execute'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `handle_interrupt'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:71:in `block in perform_query'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/share_lock.rb:186:in `yield_shares'
            from /home/zzak/code/rails/activesupport/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:70:in `perform_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:556:in `block (2 levels) in raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1011:in `block in with_raw_connection'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:983:in `with_raw_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:555:in `block in raw_execute'
            from /home/zzak/code/rails/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1129:in `log'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:554:in `raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:591:in `internal_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:173:in `exec_update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:208:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:27:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:278:in `block in _update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:412:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:277:in `_update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:622:in `update_columns'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `block in decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:40:in `with_encryption_context'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:50:in `without_encryption'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:172:in `decrypt'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:22:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `_execute': Mysql2::Error: `UPDATE `posts` SET `posts`.`title` = ?, `posts`.`body` = ? WHERE `posts`.`id` = ?` Bind parameter count (0) doesn't match number of arguments (3) (Mysql2::Error)
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `block in execute'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `handle_interrupt'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:71:in `block in perform_query'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/share_lock.rb:186:in `yield_shares'
            from /home/zzak/code/rails/activesupport/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:70:in `perform_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:556:in `block (2 levels) in raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1011:in `block in with_raw_connection'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:983:in `with_raw_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:555:in `block in raw_execute'
            from /home/zzak/code/rails/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1129:in `log'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:554:in `raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:591:in `internal_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:173:in `exec_update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:208:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:27:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:278:in `block in _update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:412:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:277:in `_update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:622:in `update_columns'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `block in decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:40:in `with_encryption_context'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:50:in `without_encryption'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:172:in `decrypt'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:22:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `_execute': Bind parameter count (0) doesn't match number of arguments (3) (Mysql2::Error)
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `block in execute'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `handle_interrupt'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:71:in `block in perform_query'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/share_lock.rb:186:in `yield_shares'
            from /home/zzak/code/rails/activesupport/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb:70:in `perform_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:556:in `block (2 levels) in raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1011:in `block in with_raw_connection'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:983:in `with_raw_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:555:in `block in raw_execute'
            from /home/zzak/code/rails/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:1129:in `log'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:554:in `raw_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:591:in `internal_execute'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:173:in `exec_update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:208:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:27:in `update'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:278:in `block in _update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:412:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:277:in `_update_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:622:in `update_columns'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `block in decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:40:in `with_encryption_context'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/contexts.rb:50:in `without_encryption'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:197:in `decrypt_attributes'
            from /home/zzak/code/rails/activerecord/lib/active_record/encryption/encryptable_record.rb:172:in `decrypt'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:22:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    E
    
    Error:
    ActiveRecord::Encryption::ConcurrencyTest#test_models_can_be_encrypted_and_decrypted_in_different_threads_concurrently:
    ActiveRecord::StatementInvalid: Mysql2::Error: Mysql2::Error: `SELECT `posts`.* FROM `posts` WHERE `posts`.`type` = ? ORDER BY `posts`.`id` DESC LIMIT ?` Commands out of sync; you can't run this command now
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `_execute'
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:5:in `block in execute'
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `handle_interrupt'
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/gems/3.2.0/gems/mysql2-0.5.6/lib/mysql2/statement.rb:4:in `execute'
        lib/active_record/connection_adapters/mysql2/database_statements.rb:71:in `block in perform_query'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/share_lock.rb:186:in `yield_shares'
        /home/zzak/code/rails/activesupport/lib/active_support/dependencies/interlock.rb:41:in `permit_concurrent_loads'
        lib/active_record/connection_adapters/mysql2/database_statements.rb:70:in `perform_query'
        lib/active_record/connection_adapters/abstract/database_statements.rb:556:in `block (2 levels) in raw_execute'
        lib/active_record/connection_adapters/abstract_adapter.rb:1011:in `block in with_raw_connection'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
        lib/active_record/connection_adapters/abstract_adapter.rb:983:in `with_raw_connection'
        lib/active_record/connection_adapters/abstract/database_statements.rb:555:in `block in raw_execute'
        /home/zzak/code/rails/activesupport/lib/active_support/notifications/instrumenter.rb:58:in `instrument'
        lib/active_record/connection_adapters/abstract_adapter.rb:1129:in `log'
        lib/active_record/connection_adapters/abstract/database_statements.rb:554:in `raw_execute'
        lib/active_record/connection_adapters/abstract/database_statements.rb:591:in `internal_execute'
        lib/active_record/connection_adapters/abstract/database_statements.rb:547:in `internal_exec_query'
        lib/active_record/connection_adapters/abstract/database_statements.rb:693:in `select'
        lib/active_record/connection_adapters/abstract/database_statements.rb:73:in `select_all'
        lib/active_record/connection_adapters/abstract/query_cache.rb:251:in `select_all'
        lib/active_record/connection_adapters/mysql2/database_statements.rb:12:in `select_all'
        lib/active_record/querying.rb:68:in `_query_by_sql'
        lib/active_record/relation.rb:1449:in `block (2 levels) in exec_main_query'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:406:in `with_connection'
        lib/active_record/connection_handling.rb:310:in `with_connection'
        lib/active_record/relation.rb:1448:in `block in exec_main_query'
        lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
        lib/active_record/relation.rb:1432:in `exec_main_query'
        lib/active_record/relation.rb:1410:in `block in exec_queries'
        lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
        lib/active_record/relation.rb:1404:in `exec_queries'
        lib/active_record/relation.rb:1181:in `load'
        lib/active_record/relation.rb:343:in `records'
        lib/active_record/relation/delegation.rb:101:in `reverse'
        lib/active_record/relation/finder_methods.rb:208:in `last'
        lib/active_record/querying.rb:24:in `last'
        test/cases/encryption/concurrency_test.rb:17:in `thread_encrypting_and_decrypting'
        test/cases/encryption/concurrency_test.rb:12:in `block (2 levels) in <class:ConcurrencyTest>'
        test/cases/encryption/concurrency_test.rb:12:in `times'
        test/cases/encryption/concurrency_test.rb:12:in `each'
        test/cases/encryption/concurrency_test.rb:12:in `collect'
        test/cases/encryption/concurrency_test.rb:12:in `block in <class:ConcurrencyTest>'
    
    Error:
    ActiveRecord::Encryption::ConcurrencyTest#test_models_can_be_encrypted_and_decrypted_in_different_threads_concurrently:
    ActiveRecord::ActiveRecordError: Cannot expire connection, it is not currently leased.
        lib/active_record/connection_adapters/abstract_adapter.rb:323:in `expire'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:572:in `block (3 levels) in checkin'
        /home/zzak/code/rails/activesupport/lib/active_support/callbacks.rb:109:in `run_callbacks'
        /home/zzak/code/rails/activesupport/lib/active_support/callbacks.rb:912:in `_run_checkin_callbacks'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:571:in `block (2 levels) in checkin'
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `synchronize'
        /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `mon_synchronize'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:568:in `block in checkin'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
        /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:567:in `checkin'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:384:in `release_connection'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:415:in `ensure in with_connection'
        lib/active_record/connection_adapters/abstract/connection_pool.rb:415:in `with_connection'
        lib/active_record/connection_handling.rb:310:in `with_connection'
        lib/active_record/persistence.rb:277:in `_update_record'
        lib/active_record/persistence.rb:622:in `update_columns'
        lib/active_record/encryption/encryptable_record.rb:197:in `block in decrypt_attributes'
        lib/active_record/encryption/contexts.rb:40:in `with_encryption_context'
        lib/active_record/encryption/contexts.rb:50:in `without_encryption'
        lib/active_record/encryption/encryptable_record.rb:197:in `decrypt_attributes'
        lib/active_record/encryption/encryptable_record.rb:172:in `decrypt'
        test/cases/encryption/concurrency_test.rb:22:in `block (2 levels) in thread_encrypting_and_decrypting'
        test/cases/encryption/concurrency_test.rb:20:in `each'
        test/cases/encryption/concurrency_test.rb:20:in `with_index'
        test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    
    /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:545:in `block (2 levels) in checkout': undefined method `verify!' for nil:NilClass (NoMethodError)
    
                  @pinned_connection.verify!
                                    ^^^^^^^^
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `synchronize'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `mon_synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:544:in `block in checkout'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:543:in `checkout'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:412:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1448:in `block in exec_main_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1432:in `exec_main_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1410:in `block in exec_queries'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1404:in `exec_queries'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1181:in `load'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:343:in `records'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:586:in `find_take'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:129:in `take'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:135:in `take!'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:118:in `find_by!'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:834:in `_find_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:749:in `block in reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1373:in `_scoping'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:548:in `scoping'
            from /home/zzak/code/rails/activerecord/lib/active_record/scoping/default.rb:51:in `unscoped'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:749:in `reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/attribute_methods/dirty.rb:64:in `reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/autosave_association.rb:241:in `reload'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/helper.rb:22:in `assert_encrypted_attribute'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:21:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:545:in `block (2 levels) in checkout': undefined method `verify!' for nil:NilClass (NoMethodError)
    
                  @pinned_connection.verify!
                                    ^^^^^^^^
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `synchronize'
            from /home/zzak/.rbenv/versions/3.2.3/lib/ruby/3.2.0/monitor.rb:202:in `mon_synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:544:in `block in checkout'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:23:in `block in synchronize'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `handle_interrupt'
            from /home/zzak/code/rails/activesupport/lib/active_support/concurrency/load_interlock_aware_monitor.rb:19:in `synchronize'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:543:in `checkout'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb:412:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/connection_handling.rb:310:in `with_connection'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1448:in `block in exec_main_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1432:in `exec_main_query'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1410:in `block in exec_queries'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1470:in `skip_query_cache_if_necessary'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1404:in `exec_queries'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1181:in `load'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:343:in `records'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:586:in `find_take'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:129:in `take'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:135:in `take!'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation/finder_methods.rb:118:in `find_by!'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:834:in `_find_record'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:749:in `block in reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:1373:in `_scoping'
            from /home/zzak/code/rails/activerecord/lib/active_record/relation.rb:548:in `scoping'
            from /home/zzak/code/rails/activerecord/lib/active_record/scoping/default.rb:51:in `unscoped'
            from /home/zzak/code/rails/activerecord/lib/active_record/persistence.rb:749:in `reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/attribute_methods/dirty.rb:64:in `reload'
            from /home/zzak/code/rails/activerecord/lib/active_record/autosave_association.rb:241:in `reload'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/helper.rb:22:in `assert_encrypted_attribute'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:21:in `block (2 levels) in thread_encrypting_and_decrypting'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `each'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `with_index'
            from /home/zzak/code/rails/activerecord/test/cases/encryption/concurrency_test.rb:20:in `block in thread_encrypting_and_decrypting'
    ```
Loading