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

net/http: Client.Do hangs (in Linux Daemon) when exported via Cgo shared library #47077

Closed
avnileshshinde opened this issue Jul 7, 2021 · 4 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@avnileshshinde
Copy link

avnileshshinde commented Jul 7, 2021

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

$ go version
version go1.16.4 linux/386

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="386"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOINSECURE="golang.org,googlesource.com"
GOMODCACHE="/home/nilesh/golang/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/nilesh/golang"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_386"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
GO386="sse2"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/nilesh/SVN/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build718813889=/tmp/go-build -gno-record-gcc-switches"

What did you do?

See Go definition of CheckConnection() function given below. I exported CheckConnection Go function as C function in .so file using following command.
go build -o mygolib.so -buildmode=c-shared mygolib.go

Then using generated .SO and .h, called exported Go function from my C test program. Below is the command I used to compile and build my C test program.

gcc -o testclient testclient.c ./mygolib.so

With this testclient program in C I am able to get the response from myClient. However when I included this .so and .h file in our existing Linux service (in C only),I am unable to make http request. Below is my Go function. Call gets blocked at below line, does not timeout or gives any error. testclient and linux service is on same machine. However from testclient function returns me the response but from linux service call gets hang.

res,err := myClient.Do(req)

//export CheckConnection
func CheckConnection() {

reqUrl,_ := url.Parse("https://www.google.com/")

req := &http.Request{
Method: "GET",
URL: reqUrl,
Header: map[string][]string{
"Content-type": {"application/json; charset=UTF-8" },
},
}

 var myClient = &http.Client{
  Timeout: time.Second * 10,
 }

res,err := myClient.Do(req)
if err!= nil {
log.Fatal("Error ",err)
}

data,_ := ioutil.ReadAll(res.Body)
res.Body.Close()

log.Print("Resp code ",res.StatusCode)
log,Print("Data ",data)
}

What did you expect to see?

res,err := myClient.Do(req)
Above call should either return me the response string or timeout error.

What did you see instead?

Call gets hand on below code line -
res,err := myClient.Do(req)

@mdlayher mdlayher changed the title Do() call of http.Client is getting hang when call from Linux service net/http: Client.Do hangs when exported via Cgo shared library Jul 7, 2021
@mknyszek
Copy link
Contributor

mknyszek commented Jul 7, 2021

Since you say that this only seems to go wrong in your service, it's hard for us to take steps toward resolving it.

If you could create a small reproducer that demonstrates the problem, that would be really helpful.

CC @neild via https://dev.golang.org/owners

@mknyszek mknyszek added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jul 7, 2021
@mknyszek mknyszek added this to the Backlog milestone Jul 7, 2021
@avnileshshinde
Copy link
Author

Sure, I will try to reproduce it with sample. But meanwhile if you could provide me some pointers around what area/parameters could can cause such kind of issues, so that I can check the service behavior from my end. Reproducing this issue with sample service may take some time.

@avnileshshinde
Copy link
Author

avnileshshinde commented Jul 26, 2021

Hello, Here is the sample code with which issue is reproducible. (Sample.zip contain goclient.c and libapp.go)
The goclient.c is the program which tries to run as daemon on CentOS 7. In this program, there are two calls to CheckConnection() function. One from main() and other from daemon process. Call from main gets succeeded where as call from daemon process hangs.

Sample.zip

@avnileshshinde avnileshshinde changed the title net/http: Client.Do hangs when exported via Cgo shared library net/http: Client.Do hangs (in Linux Daemon) when exported via Cgo shared library Jul 28, 2021
@avnileshshinde
Copy link
Author

Since you say that this only seems to go wrong in your service, it's hard for us to take steps toward resolving it.

If you could create a small reproducer that demonstrates the problem, that would be really helpful.

CC @neild via https://dev.golang.org/owners

Hi @mknyszek

I am able to reproduce this issue with sample code. I have attached same to this incident. Could you please look at this?

Regards,
Nilesh

@golang golang locked and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants