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

net/http: Post url: read tcp xx->xx: i/o timeout returns less than 1 seconds #27942

Open
jacentsao opened this Issue Sep 30, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@jacentsao

jacentsao commented Sep 30, 2018

What version of Go are you using (go version)?

$ go version
go version go1.10.3 windows/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\xx\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=G:\workspace\GO
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessag                                                                                                                                                                                               e-length=0 -fdebug-prefix-map=C:\Users\xx\AppData\Local\Temp\go-build87870614                                                                                                                                                                                               2=/tmp/go-build -gno-record-gcc-switches

What did you do?


tr = &http.Transport{
	TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	Dial:            TimeoutDialer(connectTimeout, readWriteTimeout),
}
client := &http.Client{Transport: tr,}
if req, err := client.Post(url, "application/json;charset=utf-8", body); err == nil {
    defer req.Body.Close()
   if result, err := ioutil.ReadAll(req.Body); err == nil {
       Post url: read tcp xx->xx: i/o timeout 
  }
}  else {
   
}

What did you expect to see?

no error occurs

What did you see instead?

I got a timeout error just like below when launch post request it returns error less than 1 seconds

Post url: read tcp xx->xx: i/o timeout 

@agnivade

This comment has been minimized.

Member

agnivade commented Sep 30, 2018

I think DialContext is a better choice for what you are trying to do.

In any case, we would need a full standalone code sample, rather than a snippet. Also, what is the url ? Is it an internal server ? How do we reproduce this issue ? Have you tried with 1.11 ?

@jacentsao

This comment has been minimized.

jacentsao commented Oct 1, 2018

@agnivade I add a sample code, but output is different with output my pc local. Here is my local output:

create request failed Post https://web.zhihuiji.com/sync: read tcp 192.168.5.36:56318->118.194.40.71:443: i/o timeoutpanic: Post https://web.zhihuiji.com/sync: read tcp 192.168.5.36:56318->118.194.40.71:443: i/o timeout

But run in play.golang.org:

create request failed Post https://web.zhihuiji.com/sync: dial tcp: Protocol not availablepanic: Post https://web.zhihuiji.com/sync: dial tcp: Protocol not available

After some research i found that i got a transportReadFromServerError like below:

Because of the post method, it won't retry the request though it will be okay when i retry request the same content. Why not retry when the server returns error even it's none-idempotent requests

@ALTree ALTree changed the title from Post url: read tcp xx->xx: i/o timeout returns less than 1 seconds to net/http: Post url: read tcp xx->xx: i/o timeout returns less than 1 seconds Oct 1, 2018

@agnivade agnivade added this to the Unplanned milestone Oct 1, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment