-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: the client only use one connection while downloading from the server concurrency #40944
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
Comments
What happens if you use |
Same issue with |
Thank you I am not able to reproduce the issue you reported
Five files appear to be downloaded in parallel. |
I'm sorry I don't have access to windows or the tools you use. On my machine I see several transfers start one after another, then complete as if they were working in parallel. |
On linux or macOS you can check the connections with
You can see only one connection is used to transfer the data. If you are using macOS you can also use Proxifier to check it. Just set up a local http proxy and use Proxifier to proxy the go program. |
I'm sorry those commands don't work on my machine -- i don't know why. Please understand I don't disagree that you are having a problem, but it is not clear to be that this is a problem caused by Go, not some other component between your Go program and the origin server. Writing network downloaders is a common use case for Go and there have been no issues of this sort reported for a long time (so long I cannot remember one off hand). Again, I am not saying that you are wrong, or your problem is not happening, just that this has not been isolated to the Go http stack. |
Downloading big file
You can see it's not the same time when the header is being printed. After downloader 2 finished, downloader 0's header is printed. |
It so strange that for different website I got different result. |
@gopherbot remove WaitingForInfo |
I can reproduce the issue. But it seems because of HTTP2. |
Http2 multiplexes multiple streams over a single connection. |
@WOo0W have you looked at the headers for the different servers you've tried? That will give you the HTTP version. |
The request to
The The output in the first comment of
The The request to
The response header (no HTTP version info in it):
|
Create a new transport. For various reasons new transports are not enabled for http2 by default. |
Set GODEBUG environment |
Found in https://golang.org/pkg/net/http/
After setting Transport.TLSNextProto to an empty map the client uses HTTP 1.1 and works well. |
Try creating a new client for each request. |
It works well creating a new client for each goroutine. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am downloading images from
i.pximg.net
with multiple goroutines.My code:
What did you expect to see?
The client will create 5 connections to the server and download the content.
What did you see instead?
The client created 5 connections to the server at first, but 4 connections closed immediately. Only one connection was used to transfer the data.
Output:
Proxifier log (An app which can force other apps to use a proxy)
I tried to build a local server with
echo
to test:If I changed
url
to the local test server:All 5 connections are used to download the file.
Output:
URL
https://fengshuai.oss-cn-shenzhen.aliyuncs.com/mainpage/background_home_main.png
also seems fine:I also tested
i.imgur.com
andpbs.twimg.com
, all have same issue.The text was updated successfully, but these errors were encountered: