Skip to content

net/http: GET request hangs in Linux forked process exported via Cgo shared library #47468

Closed
@avnileshshinde

Description

@avnileshshinde

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
$ 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 attached in Sample.zip. I exported CheckConnection Go function as C function in .so file using following command. This function makes http GET request to google.com using http.client.

 go build -o libapp.so -buildmode=c-shared libapp.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 -m32 -o ctest ctest.c ./libapp.so

In the C test program, I called exported CheckConnection() function from main() and from forked process. Function call from main() gets succeeded whereas function call from forked process hangs at

  res,err := myClient.Get("https://www.google.com")

Attached is the sample code reproducible. [(Sample.zip)]
Sample.zip

What did you expect to see?

Both calls to CheckConnection() should succeed.

What did you see instead?

CheckConnection() call from main() succeed and CheckConnection() call from forked process hangs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions