Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent Net/ReadTimeout error in Ruby 2.6 #751

Merged

Conversation

koic
Copy link
Contributor

@koic koic commented Mar 15, 2018

This PR fixes the following build error in Ruby 2.6.0 (ruby-head).

$ ruby --version
ruby 2.6.0dev (2018-03-07 trunk 62693) [x86_64-linux]
% bundle exec rake
(snip)

  1) Net:HTTP with WebMock when net connect is allowed should make a
  real https request if request is not stubbed
     Failure/Error: response = super(request, nil, &nil)

     Net::ReadTimeout:
       Net::ReadTimeout
     Shared Example Group: "allowing and disabling net connect" called
       from ./spec/acceptance/webmock_shared.rb:25
     Shared Example Group: "with WebMock" called from
       ./spec/acceptance/net_http/net_http_spec.rb:10
     # ./lib/webmock/http_lib_adapters/net_http.rb:97:in `block in
       request'
     # ./lib/webmock/http_lib_adapters/net_http.rb:105:in `block in
       request'
     # ./lib/webmock/http_lib_adapters/net_http.rb:137:in
       `start_with_connect_without_finish'
     # ./lib/webmock/http_lib_adapters/net_http.rb:104:in `request'
     # ./spec/acceptance/net_http/net_http_spec_helper.rb:35:in `block
       in http_request'
     # ./lib/webmock/http_lib_adapters/net_http.rb:123:in
       `start_without_connect'
     # ./lib/webmock/http_lib_adapters/net_http.rb:150:in `start'
     # ./spec/acceptance/net_http/net_http_spec_helper.rb:34:in
       `http_request'
     #
       ./spec/acceptance/shared/allowing_and_disabling_net_connect.rb:14:in
       `block (4 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # Net::ReadTimeout:
     #   Net::ReadTimeout
     #   ./lib/webmock/http_lib_adapters/net_http.rb:97:in `block in
       request'

(Errors continue after this)

https://travis-ci.org/bblimke/webmock/jobs/350668167#L942-L1202

This is because it was changed to use IO#read_nonblock based on the value of @rbuf by the following commit.
ruby/ruby@b02fc0f

This PR forces the 2nd argument tmp of IO#read_nonblock to nil by using TracePoint. So this prevents Net::ReadTimeout from occurring.

@koic koic force-pushed the prevent_net_readtimeout_error_in_ruby_2_6 branch from 50eac69 to c1badcf Compare March 15, 2018 16:43
This PR fixes the following build error in Ruby 2.6.0 (ruby-head).

```console
$ ruby --version
ruby 2.6.0dev (2018-03-07 trunk 62693) [x86_64-linux]
% bundle exec rake
(snip)

  1) Net:HTTP with WebMock when net connect is allowed should make a
  real https request if request is not stubbed
     Failure/Error: response = super(request, nil, &nil)

     Net::ReadTimeout:
       Net::ReadTimeout
     Shared Example Group: "allowing and disabling net connect" called
       from ./spec/acceptance/webmock_shared.rb:25
     Shared Example Group: "with WebMock" called from
       ./spec/acceptance/net_http/net_http_spec.rb:10
     # ./lib/webmock/http_lib_adapters/net_http.rb:97:in `block in
       request'
     # ./lib/webmock/http_lib_adapters/net_http.rb:105:in `block in
       request'
     # ./lib/webmock/http_lib_adapters/net_http.rb:137:in
       `start_with_connect_without_finish'
     # ./lib/webmock/http_lib_adapters/net_http.rb:104:in `request'
     # ./spec/acceptance/net_http/net_http_spec_helper.rb:35:in `block
       in http_request'
     # ./lib/webmock/http_lib_adapters/net_http.rb:123:in
       `start_without_connect'
     # ./lib/webmock/http_lib_adapters/net_http.rb:150:in `start'
     # ./spec/acceptance/net_http/net_http_spec_helper.rb:34:in
       `http_request'
     #
       ./spec/acceptance/shared/allowing_and_disabling_net_connect.rb:14:in
       `block (4 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # Net::ReadTimeout:
     #   Net::ReadTimeout
     #   ./lib/webmock/http_lib_adapters/net_http.rb:97:in `block in
       request'

(Errors continue after this)
```

https://travis-ci.org/bblimke/webmock/jobs/350668167#L942-L1202

This is because it was changed to use `IO#read_nonblock` based on the
value of `@rbuf` by the following commit.
ruby/ruby@b02fc0f

This PR forces the 2nd argument `tmp` of `IO#read_nonblock` to `nil` by using
`TracePoint`. So this prevents `Net::ReadTimeout` from occurring.
@koic koic force-pushed the prevent_net_readtimeout_error_in_ruby_2_6 branch from c1badcf to 1cc36e5 Compare March 15, 2018 16:46
@bblimke
Copy link
Owner

bblimke commented Apr 29, 2018

@koic Clever! Thank you.

@bblimke bblimke merged commit 332af13 into bblimke:master Apr 29, 2018
@koic koic deleted the prevent_net_readtimeout_error_in_ruby_2_6 branch April 29, 2018 09:15
ko1 added a commit to ko1/webmock that referenced this pull request Dec 12, 2018
if `super` raise an exception, this very danger TracePoint is not disabled.
This is why https://bugs.ruby-lang.org/issues/15400

This change is introduced at: bblimke#751

Anyway, this approach is very danger (for example, `tmp` variable name is not exposed API), so that pls re-consider to use this technique.
@ko1 ko1 mentioned this pull request Dec 12, 2018
tagliala added a commit to Coveralls-Community/coveralls-ruby that referenced this pull request Dec 26, 2018
Tests against Ruby 2.6 are going to fail.

May be related to bblimke/webmock#751
tagliala added a commit to Coveralls-Community/coveralls-ruby that referenced this pull request Dec 26, 2018
Tests against Ruby 2.6 are going to fail.

May be related to bblimke/webmock#751
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants