I'm seeing "http2: no cached connection was available" failures from
http.Client when I start many (~hundreds) requests at once. (This issue was
also posted to golang-nuts@ in April
<https://groups.google.com/d/topic/golang-nuts/0YEWYwBOJPI/discussion>,
with no response)

I may not understand correctly, but I thought this kind of usage was fine
with HTTP 1.1 and net/http, because the spec mandates a max number of
outgoing connections to any given host, so http.Client throttles open
connections and effectively queues requests past that. The http2 package
seems not to do the same. That might be correct according to the spec (I
don't know), but makes using http.Client weird -- I need to rate limit its
usage if the server is HTTP 2, but it does rate limiting for me if the
server is HTTP 1.1.

Is my understanding correct? Is this a bug? Is the expectation that my app
should be rate limiting, regardless of server version?

Also, It seems the error being returned is exported
<https://godoc.org/golang.org/x/net/http2#pkg-variables> in the http2
package, but is not exported in the bundled version
<https://golang.org/src/net/http/h2_bundle.go#L4775> in net/http. If it was
exported, I think I could at least retry on my own, but perhaps that's not
the intended usage anyway.

I wrote this program <https://play.golang.org/p/zKthX7Y9RW> hitting
https://www.google.com/ to demonstrate -- here are a few run results:

$ GODEBUG=http2client=0 go run /tmp/foo.go
$ GODEBUG=http2client=0 go run /tmp/foo.go
$ GODEBUG=http2client=0 go run /tmp/foo.go
$ GODEBUG=http2client=0 go run /tmp/foo.go
$ GODEBUG=http2client=0 go run /tmp/foo.go

$ GODEBUG=http2client=1 go run /tmp/foo.go
Get https://www.google.com/: http2: no cached connection was available
Get https://www.google.com/: http2: no cached connection was available
Get https://www.google.com/: http2: no cached connection was available
...
$ GODEBUG=http2client=1 go run /tmp/foo.go
Get https://www.google.com/: http2: no cached connection was available
$ GODEBUG=http2client=1 go run /tmp/foo.go
$ GODEBUG=http2client=1 go run /tmp/foo.go
Get https://www.google.com/: http2: no cached connection was available
Get https://www.google.com/: http2: no cached connection was available
Get https://www.google.com/: http2: no cached connection was available
...
$ GODEBUG=http2client=1 go run /tmp/foo.go
Get https://www.google.com/: http2: no cached connection was available
Get https://www.google.com/: http2: no cached connection was available
Get https://www.google.com/: http2: no cached connection was available
...

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to