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

package GOB "GobEncode()" looping #41496

Closed
archfoe opened this issue Sep 19, 2020 · 1 comment
Closed

package GOB "GobEncode()" looping #41496

archfoe opened this issue Sep 19, 2020 · 1 comment

Comments

@archfoe
Copy link

@archfoe archfoe commented Sep 19, 2020

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

$ go version
go version go1.15.2 linux/amd64

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="amd64"
GOBIN=""
GOCACHE="/home/xxx/.cache/go-build"
GOENV="/home/xxx/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/xxx/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xxx/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/snap/go/6439"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/snap/go/6439/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build340516344=/tmp/go-build -gno-record-gcc-switches"

What did you do?

In package:

package gob

	switch ut.externalEnc {
	case xGob:
LINE:478	data, err = v.Interface().(GobEncoder).GobEncode() //<--HERE!!!!
	case xBinary:

What did you expect to see?

I had a code:

func (ad AgentData) GobEncode() ([]byte, error) {
	var byteData bytes.Buffer
	err := gob.NewEncoder(&byteData).Encode(ad)
	return byteData.Bytes(), err
}

end it was creating endless loop from

	err := gob.NewEncoder(&byteData).Encode(ad)

back to calling the the function:

func (ad AgentData) GobEncode() ([]byte, error) {

What did you see instead?

I traced the code and found that my function:

func (ad AgentData) GobEncode() ([]byte, error)

has the same name as the package GOB function:

LINE:478	data, err = v.Interface().(GobEncoder).GobEncode() //<--HERE!!!!

The fix was to rename my function to a different name but still this is a bug.

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Sep 20, 2020

It sounds like this is working as intended. encoding/gob provides extension points for users to write optional, custom encoding methods (see https://golang.org/pkg/encoding/gob/#GobEncoder), and you accidentally implemented that interface.

@mdempsky mdempsky closed this Sep 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.