socketry / async-http

MIT License
298 stars 45 forks source link

The "multiple requests" example fails #112

Closed mcampbell closed 1 year ago

mcampbell commented 1 year ago

Is this user error? The first example works fine, but the second one using a barrier fails with the following error. It's a copy/paste of the example.

The same happens with ruby 3.2.0 (also under rbenv)

 1.08s     warn: Async::HTTP::Client [oid=0x280] [ec=0x294] [pid=57764] [2023-02-12 12:55:00 -0500]
               | Waiting for Async::HTTP::Protocol::HTTPS pool to drain: #<Async::Pool::Controller(1/∞) 2/4294967295/3>
 1.08s     warn: Async::Task [oid=0x2a8] [ec=0x2bc] [pid=57764] [2023-02-12 12:55:00 -0500]
               | Task may have ended with unhandled exception.
               |   Zlib::DataError: invalid stored block lengths
               |   → /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/inflate.rb:30 in `inflate'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/inflate.rb:30 in `read'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/readable.rb:69 in `each'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/readable.rb:80 in `join'
               |     /Users/michael.camp 1.08s     warn: Async::HTTP::Client [oid=0x280] [ec=0x294] [pid=57764] [2023-02-12 12:55:00 -0500]
               | Waiting for Async::HTTP::Protocol::HTTPS pool to drain: #<Async::Pool::Controller(1/∞) 1/4294967295/3>
bell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/reader.rb:25 in `read'
               |     test2.rb:15 in `block (3 levels) in <main>'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/async-2.3.1/lib/async/task.rb:107 in `block in run'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/async-2.3.1/lib/async/task.rb:248 in `block in schedule'
 1.11s     warn: Async::Task [oid=0x2d0] [ec=0x2e4] [pid=57764] [2023-02-12 12:55:00 -0500]
               | Task may have ended with unhandled exception.
               |   Zlib::DataError: invalid stored block lengths
               |   → /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/inflate.rb:30 in `inflate'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/inflate.rb:30 in `read'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/readable.rb:69 in `each'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/readable.rb:80 in `join'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/reader.rb:25 in `read'
               |     test2.rb:15 in `block (3 levels) in <main>'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/async-2.3.1/lib/async/task.rb:107 in `block in run'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/async-2.3.1/lib/async/task.rb:248 in `block in schedule'
 1.12s     warn: Async::Task [oid=0x2f8] [ec=0x294] [pid=57764] [2023-02-12 12:55:00 -0500]
               | Task may have ended with unhandled exception.
               |   Zlib::DataError: invalid stored block lengths
               |   → /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/inflate.rb:30 in `inflate'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/inflate.rb:30 in `read'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/readable.rb:69 in `each'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/readable.rb:80 in `join'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/protocol-http-0.24.1/lib/protocol/http/body/reader.rb:25 in `read'
               |     test2.rb:15 in `block (3 levels) in <main>'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/async-2.3.1/lib/async/task.rb:107 in `block in run'
               |     /Users/michael.campbell/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/async-2.3.1/lib/async/task.rb:248 in `block in schedule'

Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    async (2.3.1)
      console (~> 1.10)
      io-event (~> 1.1)
      timers (~> 4.1)
    async-http (0.60.1)
      async (>= 1.25)
      async-io (>= 1.28)
      async-pool (>= 0.2)
      protocol-http (~> 0.24.0)
      protocol-http1 (~> 0.15.0)
      protocol-http2 (~> 0.15.0)
      traces (>= 0.8.0)
    async-io (1.34.3)
      async
    async-pool (0.3.12)
      async (>= 1.25)
    console (1.16.2)
      fiber-local
    fiber-local (1.0.0)
    io-event (1.1.6)
    protocol-hpack (1.4.2)
    protocol-http (0.24.1)
    protocol-http1 (0.15.0)
      protocol-http (~> 0.22)
    protocol-http2 (0.15.0)
      protocol-hpack (~> 1.4)
      protocol-http (~> 0.18)
    timers (4.3.5)
    traces (0.8.0)

PLATFORMS
  ruby

DEPENDENCIES
  async-http

BUNDLED WITH
   2.4.1
mcampbell commented 1 year ago

I'm leaving this as-is in case the author wants to fix the example, but swapping out google in favor of ...

response = internet.get "https://duckduckgo.com/?q=#{topic}"

"worked", in that it didn't fail, but I'm getting 302 response codes. Probably that's on DDG's side.

Not sure if you want to close this or not.

ioquatix commented 1 year ago

Hmm, that's odd. I'll take a look.

ioquatix commented 1 year ago

This is a regression, I'll need to investigate it.

ioquatix commented 1 year ago

There was an off-by-one error in padding handling. Padding is a pretty obscure feature of HTTP/2, but it was used by Google's search results and was corrupting the response data, which was then failing to decompress.

ioquatix commented 1 year ago

Okay, I released an update to protocol-http2 v0.15.1 which fixes this issue. Can you please check it? Thanks!

mcampbell commented 1 year ago

Success!

~/dev/async-test via 💎 v3.1.2 
at 09:14 ❯ ruby ./multiple-requests.rb 
Found python: 59 times.
Found rust: 73 times.
Found ruby: 59 times.

Not sure what your closing protocol is; I can close the ticket if you like. =D

Thanks!

ioquatix commented 1 year ago

Thanks for reporting back!