read_body called twice #32

Closed
bblimke opened this Issue Aug 9, 2010 · 10 comments

Projects

None yet

2 participants

@bblimke
Owner
bblimke commented Aug 9, 2010
irb(main):001:0> require 'webmock'
=> true
irb(main):002:0> require 'open-uri'
=> true
irb(main):003:0> WebMock.allow_net_connect!
=> true
irb(main):004:0> open('http://www.bbc.co.uk')
IOError: Net::HTTPOK#read_body called twice
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2167:in `read_body'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:257:in `open_http'
from /Library/Ruby/Gems/1.8/gems/webmock-1.3.2/lib/webmock/http_lib_adapters/net_http.rb:76:in `request'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:248:in `open_http'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:543:in `start'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:242:in `open_http'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:616:in `buffer_open'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:162:in `catch'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:518:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:30:in `open'
from (irb):4
@bblimke
Owner
bblimke commented Aug 10, 2010

It was a problem with Net::HTTP adapter where it was patching response object to be re-read, only if callback was declared. Now it is patched for each real request.
Fixed in version 1.3.4

@phocke
phocke commented Sep 21, 2010

I'm using 1.3.5 and still get this error ;/

@bblimke
Owner
bblimke commented Sep 21, 2010

I don't get this error. What exactly version of ruby do you use?

Is it the same code snippet?
require 'webmock'
require 'open-uri'
WebMock.allow_net_connect!
open('http://www.bbc.co.uk')

@phocke
phocke commented Sep 23, 2010

Sorry for such a delay.

The thing is

when I run my tests with say "rake test:units"
I get the error
but when I run single tests ("rake test:article" or whatever)
I don't get the error.
Is it possible that calling WebMock.allow_net_connect! twice without calling WebMock.disable_net_connect! causes the error?

@phocke
phocke commented Sep 23, 2010

Small update - I tried this approach:

class ActiveSupport::TestCase
  setup do
    WebMock.allow_net_connect!
  end

  teardown do 
    WebMock.disable_net_connect!
  end
end

got rid of all other calls to WebMock.allow... and WebMock.disable... from my tests but still get the errors

@bblimke
Owner
bblimke commented Sep 23, 2010

Calling WebMock.allow_net_connect! twice is not the cause.

What version of ruby do you use?
Are you able to provide a failing snippet of code?
Are you getting exactly the same "IOError: Net::HTTPOK#read_body called twice" error?

@phocke
phocke commented Sep 23, 2010

I get exactly
IOError: Net::HTTPOK#read_body called twice

I use
ree-1.8.7-2010.02 [ x86_64 ]
installed with rvm

I'll try to provide the failing test for you, but I think it's gonna take some time to extract it from my repo(unfortunately its private one, with closed source)

@bblimke
Owner
bblimke commented Sep 23, 2010

It's tested on 1.8.7 so ruby compatibility is not the issue.

Is it possible you have some other library included which also modifies Net::HTTP and reads the response?

I'm on #webmock on irc.freenode.net

@bblimke
Owner
bblimke commented Sep 27, 2010

It was a bug introduced in VCR 1.1.2. It should work with VCR from head and will be fixed in the next release of VCR.

@phocke
phocke commented Sep 27, 2010

Thank you very much!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment