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

Webmock breaks HTTP::Client.get(“https…”) with Closed stream (IO::Error) #41

Open
msa7 opened this issue Mar 25, 2020 · 2 comments · May be fixed by #42
Open

Webmock breaks HTTP::Client.get(“https…”) with Closed stream (IO::Error) #41

msa7 opened this issue Mar 25, 2020 · 2 comments · May be fixed by #42

Comments

@msa7
Copy link
Contributor

msa7 commented Mar 25, 2020

Webmock breaks

    require "webmock"
    WebMock.allow_net_connect = true
    response = HTTP::Client.get("https://api.exchangeratesapi.io/latest?base=EUR")
    p response

I got exception

Closed stream (IO::Error)
         from /usr/share/crystal/src/io.cr:128:5 in 'check_open'
         from /usr/share/crystal/src/io/buffered.cr:99:5 in 'peek'
         from /usr/share/crystal/src/io.cr:632:37 in 'gets'
         from /usr/share/crystal/src/io.cr:591:5 in 'gets'
         from /usr/share/crystal/src/io.cr:814:5 in 'read_line:chomp'
         from /usr/share/crystal/src/http/content.cr:205:7 in 'read_chunk_size'
         from /usr/share/crystal/src/http/content.cr:187:26 in 'next_chunk'
         from /usr/share/crystal/src/http/content.cr:120:7 in 'read'
         from /usr/share/crystal/src/io.cr:554:29 in 'gets_to_end'
         from /usr/share/crystal/src/http/client/response.cr:81:15 in 'consume_body_io'
         from lib/webmock/src/webmock/core_ext.cr:12:7 in 'exec_internal'
         from /usr/share/crystal/src/http/client.cr:576:5 in 'exec'
         from /usr/share/crystal/src/http/client.cr:698:5 in 'exec'
         from /usr/share/crystal/src/http/client.cr:730:7 in 'exec'
         from /usr/share/crystal/src/http/client.cr:402:3 in ‚get

Without webmock all works as expected.

P.S. Original question https://stackoverflow.com/questions/60847886/closed-stream-ioerror-with-httpclient-gethttps

@jwoertink
Copy link

I just ran in to this as well. Any Lucky app using this shard, and LuckyFlow will hit this because LuckyFlow reaches out to Google to fetch chromedriver.

@straight-shoota
Copy link

As a general advice, I'd recomend against intrusive mocking mechanisms like webmock. If you can avoid it, don't use it. It's not always easy, of course.
But often it's simply possible to make a HTTP::Client instance configurable, so you can hook it up directly to a mock backend.

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 a pull request may close this issue.

3 participants