From bb8ad695f4e594499551b32db3274deddd6b5b60 Mon Sep 17 00:00:00 2001 From: Jonathan Hefner Date: Sun, 1 Oct 2023 15:22:05 -0500 Subject: [PATCH] Fix AS::MessagePack with ENV["RAILS_MAX_THREADS"] `ENV` values are strings, so `ENV["RAILS_MAX_THREADS"]` must be parsed as an int. Unfortunately, `MessagePack::Factory::Pool::MemberPool` does not expose a method to check its member count, so the most we can assert is that roundtripping works as expected. Fixes #49446. --- .../lib/active_support/message_pack/serializer.rb | 2 +- .../test/message_pack/shared_serializer_tests.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/message_pack/serializer.rb b/activesupport/lib/active_support/message_pack/serializer.rb index 52c8e54392448..c5ce8e18ae0c3 100644 --- a/activesupport/lib/active_support/message_pack/serializer.rb +++ b/activesupport/lib/active_support/message_pack/serializer.rb @@ -51,7 +51,7 @@ def message_pack_pool install_unregistered_type_handler message_pack_factory.freeze end - message_pack_factory.pool(ENV.fetch("RAILS_MAX_THREADS") { 5 }) + message_pack_factory.pool(ENV.fetch("RAILS_MAX_THREADS", 5).to_i) end end diff --git a/activesupport/test/message_pack/shared_serializer_tests.rb b/activesupport/test/message_pack/shared_serializer_tests.rb index e590e6fa4e3fe..f70e474fb254b 100644 --- a/activesupport/test/message_pack/shared_serializer_tests.rb +++ b/activesupport/test/message_pack/shared_serializer_tests.rb @@ -140,6 +140,15 @@ module MessagePackSharedSerializerTests test "roundtrips ActiveSupport::HashWithIndifferentAccess" do assert_roundtrip ActiveSupport::HashWithIndifferentAccess.new(a: true, b: 2, c: "three") end + + test "works with ENV['RAILS_MAX_THREADS']" do + original_env = ENV.to_h + ENV["RAILS_MAX_THREADS"] = "1" + + assert_roundtrip "value" + ensure + ENV.replace(original_env) + end end private