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: Transport.Clone returns broken transport #67284

Closed
AidanWelch opened this issue May 10, 2024 · 2 comments
Closed

net/http: Transport.Clone returns broken transport #67284

AidanWelch opened this issue May 10, 2024 · 2 comments

Comments

@AidanWelch
Copy link

Go version

go version go1.22.2 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/aidan/.cache/go-build'
GOENV='/home/aidan/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/aidan/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/aidan/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/snap/go/10585'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/snap/go/10585/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/aidan/test/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3513958785=/tmp/go-build -gno-record-gcc-switches'

What did you do?

package main

import (
	"fmt"
	"io"
	"net/http"
)

func main() {
	originalTransport := &http.Transport{}
	clonedTransport := originalTransport.Clone()

	clonedClient := &http.Client{
		Transport: clonedTransport,
	}

	clonedResp, err := clonedClient.Get("https://api.ipify.org")
	if err == nil {
		clonedBodyBuf, _ := io.ReadAll(clonedResp.Body)
		clonedResp.Body.Close()
		fmt.Println("Cloned: ", string(clonedBodyBuf))
	} else {
		fmt.Println(err.Error())
	}
}

What did you see happen?

Get "https://api.ipify.org": net/http: HTTP/1.x transport connection broken: malformed HTTP response "\x00\x00\x12\x04\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00d\x00\x04\x00\x01\x00\x00\x00\x05\x00\xff\xff\xff\x00\x00\x04\b\x00\x00\x00\x00\x00\x7f\xff\x00\x00\x00\x00\b\a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"

What did you expect to see?

Cloned: [IP Address]
@AidanWelch
Copy link
Author

Also, this bug itself seems to be the root cause for #39302, so maybe renaming that issue would be useful if this will be closed as a duplicate.

@seankhliao
Copy link
Member

Duplicate of #39302

@seankhliao seankhliao marked this as a duplicate of #39302 May 11, 2024
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants