Skip to content

FiberError when using Selenium #257

Closed
gavinhughes opened this Issue Jan 17, 2013 · 8 comments

2 participants

@gavinhughes

FiberError is raised using around hooks like so:

VCR.configure do |c|
   c.hook_into :fakeweb
   c.cassette_library_dir = Rails.root.join('spec', 'support', 'vcr_episodes')
   c.around_http_request do |request|
       name = request.uri.gsub(/\W/, '_')
       VCR.use_cassette(name, record: :new_episodes, &request)
   end
end

The setup is as in http://asciicasts.com/episodes/288-billing-with-stripe.

The FiberError is raised after Stripe responds with a token, and the form is submitted by Javascript.

Using Ruby 2.0.0-preview1 and Rails 3.2.9. Full Gemfile: https://gist.github.com/4552586.

@myronmarston
VCR member

Thanks for reporting this!

It's hard for me to go from this to something reproducible, without taking lots of time watching the rails cast and understanding exactly what steps you took to get it to that state. For example, there's this repo with 2 directories--which do I use? Above you reference the spec/support directory, but neither of the railscast directories have a spec subdirectory. What command did you run to trigger the error?

Any chance you can push what you have to a public github repo (potentially to a branch, or whatever), with explicit instructions (e.g. run bundle install, then run commands X, Y and Z) to reproduce?

@gavinhughes

@myronmarston Here's a replication of the bug:

https://github.com/gavinhughes/VCR-FiberError-debug/tree/master/saas-after

bundle
rake db:setup
rspec

This is on Ruby 2.0.0-preview1. Not tested on other Rubies.

@myronmarston
VCR member

So I found the problem. Here's your around_http_request hook:

  c.around_http_request do |request|
    name = request.uri.gsub(/\W/, '_')
    VCR.insert_cassette(name, record: :new_episodes, &request)
  end

Notice that you're using VCR.insert_cassette, not VCR.use_cassette. VCR.insert_cassette does not take a block (well, technically, every ruby method takes a block, but like many, this method ignores it). That means that it never yields to the block, which means proceed is never called on the request as the error message says. VCR.use_cassette wraps a block by using VCR.insert_cassette before yielding and VCR.eject_cassette after yielding.

The snippet you pasted above uses VCR.use_cassette, though -- not sure how you wound up with insert_cassette in the actual code.

@gavinhughes

Oops. That should've been VCR.use_cassette. I just updated the repo. It still fails with use_cassette.

@myronmarston
VCR member

Oops. That should've been VCR.use_cassette. I just updated the repo. It still fails with use_cassette.

Hmm...I'll dig into some more then. I thought it was working for me last night when I changed it to use_cassette, though.

With use_cassette does it fail right away or take a while? With insert_cassette it failed immediately, so when the use_cassette got past that part I assumed it was working...

@myronmarston
VCR member

Thanks, I can repro it now. I found the source of the problem:

FiberError: fiber called across threads

I assumed FiberError could only happen on a dead fiber and didn't think about the multi threaded case. VCR isn't properly thread safe (see #200) but I'm trying to see if I can fix it.

@myronmarston
VCR member

I have a fix for this issue in #258.

Note, however, that VCR is not threadsafe (see #200) and it looks like you're using multiple threads...so you may experience other issues.

Want to give the code in #258 a shot before I merge it in?

@gavinhughes

That fix solves it. Thanks, Myron.

@myronmarston myronmarston added a commit that closed this issue Jan 20, 2013
@myronmarston myronmarston Fix issue with `around_http_request` when using multiple threads.
Fibers cannot be shared across threads, and you would get an error
when using this feature with threads:

FiberError: fiber called across threads

Actually, we were rescuing FiberError and transforming it into an even more confusing error:

Your around_http_request hook declared at <location> must call #proceed on the yielded request but did not.

Note that VCR is not thread safe (see #200) but this brings it a bit closer.

Fixes #257.
25467d5
@plukevdh plukevdh added a commit to plukevdh/vcr that referenced this issue Apr 22, 2013
@myronmarston myronmarston Fix issue with `around_http_request` when using multiple threads.
Fibers cannot be shared across threads, and you would get an error
when using this feature with threads:

FiberError: fiber called across threads

Actually, we were rescuing FiberError and transforming it into an even more confusing error:

Your around_http_request hook declared at <location> must call #proceed on the yielded request but did not.

Note that VCR is not thread safe (see #200) but this brings it a bit closer.

Fixes #257.
200a4b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.