Fix for Ruby 3.1: Use fiber-local var for global_hook_disabled_requests#907
Conversation
Previously the finalizer being registered failed on Ruby trunk because finalizers are passed an argument and the lambda didn't accept one. I think it's simpler here to just use a fiber-local variable and have our array cleaned up automatically when the thread exits without need of a finalizer.
|
@jhawthorn Would you be able to make a CHANGELOG line which summarizes this change? (If you don't get around to, I'll get to it, at some point.) |
|
With the release of Ruby 3.1.0 a few days ago, would it be possible to cut and release a new VCR release that includes this fix? |
|
+1 |
|
Followin SemVer, that's a new major, hold on to your hats. (Well, Faraday changes made me register this #918, so any headgear-holding needs to continue for a little longer.) |
|
@olleolleolle is there a way to just ship this as a patch release on top of 6.0.0, without all of the other commits? Or is this specifically what is messing up Faraday? Or is VCR's integration with Faraday going to be problematic regardless? It's just a shame to have this gate an otherwise clean upgrade to Ruby 3.1! |
You can put this in your # FIXME(uwe): Remove when fixed
# https://github.com/vcr/vcr/pull/907/files
module VCR
class LibraryHooks
# @private
module WebMock
extend self
def with_global_hook_disabled(request)
global_hook_disabled_requests << request
begin
yield
ensure
global_hook_disabled_requests.delete(request)
end
end
def global_hook_disabled?(request)
requests = Thread.current[:_vcr_webmock_disabled_requests]
requests && requests.include?(request)
end
def global_hook_disabled_requests
Thread.current[:_vcr_webmock_disabled_requests] ||= []
end
end
end
end
# EMXIF |
|
I just created this patch (to be placed in # frozen_string_literal: true
if Rails.env.test?
unless Gem.loaded_specs["vcr"].version == Gem::Version.create("6.0.0")
raise "This patch is very likely already in the next VCR release after 6.0.0"
end
require "vcr/library_hooks/webmock"
module VCR
class LibraryHooks
module WebMock
def global_hook_disabled?(request)
requests = Thread.current[:_vcr_webmock_disabled_requests]
requests && requests.include?(request)
end
def global_hook_disabled_requests
Thread.current[:_vcr_webmock_disabled_requests] ||= []
end
end
end
end
end@donv Wow, pretty much the same idea, just minutes apart 😉 |
+1 Since this was merged a while ago, there really needs to be a patch release here. In the meantime: gem 'vcr', github: 'vcr/vcr' #Edge version for Ruby 3.1 support🤷 |
|
Looks to be released as a part of VCR 6.1 |
Thanks! I put this in my project, but I'm getting this error now, any ideas? |
Previously the finalizer being registered failed on Ruby trunk because finalizers are passed an argument and the lambda didn't accept one.
I think it's simpler here to just use a fiber-local (we could use a thread-local, but my gut feeling here was to use fiber-local) variable and have our array cleaned up automatically when the thread exits without need of a finalizer.