Skip to content

Commit

Permalink
Merge pull request #873 from kipply/dont-tracepoint
Browse files Browse the repository at this point in the history
Replace rbuf_fill modification with duplication of core library
  • Loading branch information
bblimke authored Jan 29, 2020
2 parents a44eb00 + bf418ec commit 7a36d3c
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions lib/webmock/http_lib_adapters/net_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,22 @@ def initialize(io, *args, **kwargs)
end

if RUBY_VERSION >= '2.6.0'
# https://github.com/ruby/ruby/blob/7d02441f0d6e5c9d0a73a024519eba4f69e36dce/lib/net/protocol.rb#L208
# Modified version of method from ruby, so that nil is always passed into orig_read_nonblock to avoid timeout
def rbuf_fill
current_thread_id = Thread.current.object_id

trace = TracePoint.trace(:line) do |tp|
next unless Thread.current.object_id == current_thread_id
if tp.binding.local_variable_defined?(:tmp)
tp.binding.local_variable_set(:tmp, nil)
end
end

super
ensure
trace.disable
case rv = @io.read_nonblock(BUFSIZE, nil, exception: false)
when String
return if rv.nil?
@rbuf << rv
rv.clear
return
when :wait_readable
@io.to_io.wait_readable(@read_timeout) or raise Net::ReadTimeout
when :wait_writable
@io.to_io.wait_writable(@read_timeout) or raise Net::ReadTimeout
when nil
raise EOFError, 'end of file reached'
end while true
end
end
end
Expand Down

0 comments on commit 7a36d3c

Please sign in to comment.