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

encoding/gob: oom on doubly linked list #66951

Closed
Septrum101 opened this issue Apr 21, 2024 · 4 comments
Closed

encoding/gob: oom on doubly linked list #66951

Septrum101 opened this issue Apr 21, 2024 · 4 comments

Comments

@Septrum101
Copy link

Septrum101 commented Apr 21, 2024

Go version

go version go1.22.2 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='0'
GOMOD='/mnt/d/Senis/GolandProjects/apronLEDPanel/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 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1870856540=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I use gob.Encode to save a doubly linked list.
This is the struct

type FADS struct {
	FID                string `json:"FID"`
	NodeDataID         uint   `json:"NodeDataID"`
	NodeID             uint   `json:"NodeID"`
	NodeName           string `json:"NodeName"`
	NodeTime           string `json:"NodeTime"`
	FromClient         string `json:"FromClient"`
	FromUserName       string `json:"FromUserName"`
	FromUserMobile     string `json:"FromUserMobile"`
	FromUserDepartment string `json:"FromUserDepartment"`

	Prev *FADS
	Next *FADS
}

What did you see happen?

it will casue oom.

 time="2024-04-21T19:29:51+08:00" level=debug msg="write progresses to cache"
 runtime: goroutine stack exceeds 1000000000-byte limit
 runtime: sp=0xc034eba318 stack=[0xc034eba000, 0xc054eba000]
 fatal error: stack overflow
 runtime stack:
 runtime.throw({0x8b26bd?, 0xc000067e68?})
         runtime/panic.go:1023 +0x5c fp=0xc000067e18 sp=0xc000067de8 pc=0x43803c
 runtime.newstack()
         runtime/stack.go:1103 +0x5bd fp=0xc000067fc8 sp=0xc000067e18 pc=0x45359d
 runtime.morestack()
         runtime/asm_amd64.s:616 +0x7a fp=0xc000067fd0 sp=0xc000067fc8 pc=0x46b47a
 goroutine 1 gp=0xc0000061c0 m=2 mp=0xc00004e808 [running]:
 runtime.deductAssistCredit(0x38?)
         runtime/malloc.go:1337 +0x70 fp=0xc034eba328 sp=0xc034eba320 pc=0x40e850
 runtime.mallocgc(0x38, 0x880ea0, 0x1)
         runtime/malloc.go:1025 +0xcc fp=0xc034eba3b0 sp=0xc034eba328 pc=0x40dfac
 runtime.newobject(0x890100?)
         runtime/malloc.go:1390 +0x25 fp=0xc034eba3d8 sp=0xc034eba3b0 pc=0x40e925
 encoding/gob.(*Encoder).newEncoderState(...)
         encoding/gob/encode.go:82
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:310 +0xc5 fp=0xc034eba498 sp=0xc034eba3d8 pc=0x75e4a5
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e6c0, {0x890100?, 0xc0000e45a0?, 0xc007d9e680?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034eba4f8 sp=0xc034eba498 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034eba5b8 sp=0xc034eba4f8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e680, {0x890100?, 0xc0000e42d0?, 0xc007d9e640?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034eba618 sp=0xc034eba5b8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034eba6d8 sp=0xc034eba618 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e640, {0x890100?, 0xc0000e45a0?, 0xc007d9e600?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034eba738 sp=0xc034eba6d8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034eba7f8 sp=0xc034eba738 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e600, {0x890100?, 0xc0000e42d0?, 0xc007d9e5c0?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034eba858 sp=0xc034eba7f8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034eba918 sp=0xc034eba858 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e5c0, {0x890100?, 0xc0000e45a0?, 0xc007d9e580?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034eba978 sp=0xc034eba918 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebaa38 sp=0xc034eba978 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e580, {0x890100?, 0xc0000e42d0?, 0xc007d9e540?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebaa98 sp=0xc034ebaa38 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebab58 sp=0xc034ebaa98 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e540, {0x890100?, 0xc0000e45a0?, 0xc007d9e500?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebabb8 sp=0xc034ebab58 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebac78 sp=0xc034ebabb8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e500, {0x890100?, 0xc0000e42d0?, 0xc007d9e4c0?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebacd8 sp=0xc034ebac78 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebad98 sp=0xc034ebacd8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e4c0, {0x890100?, 0xc0000e45a0?, 0xc007d9e480?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebadf8 sp=0xc034ebad98 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebaeb8 sp=0xc034ebadf8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e480, {0x890100?, 0xc0000e42d0?, 0xc007d9e440?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebaf18 sp=0xc034ebaeb8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebafd8 sp=0xc034ebaf18 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e440, {0x890100?, 0xc0000e45a0?, 0xc007d9e400?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebb038 sp=0xc034ebafd8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebb0f8 sp=0xc034ebb038 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e400, {0x890100?, 0xc0000e42d0?, 0xc007d9e3c0?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebb158 sp=0xc034ebb0f8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebb218 sp=0xc034ebb158 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e3c0, {0x890100?, 0xc0000e45a0?, 0xc007d9e380?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebb278 sp=0xc034ebb218 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebb338 sp=0xc034ebb278 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e380, {0x890100?, 0xc0000e42d0?, 0xc007d9e340?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebb398 sp=0xc034ebb338 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebb458 sp=0xc034ebb398 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e340, {0x890100?, 0xc0000e45a0?, 0xc007d9e300?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebb4b8 sp=0xc034ebb458 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebb578 sp=0xc034ebb4b8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e300, {0x890100?, 0xc0000e42d0?, 0xc007d9e2c0?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebb5d8 sp=0xc034ebb578 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebb698 sp=0xc034ebb5d8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e2c0, {0x890100?, 0xc0000e45a0?, 0xc007d9e280?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebb6f8 sp=0xc034ebb698 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebb7b8 sp=0xc034ebb6f8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e280, {0x890100?, 0xc0000e42d0?, 0xc007d9e240?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebb818 sp=0xc034ebb7b8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebb8d8 sp=0xc034ebb818 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e240, {0x890100?, 0xc0000e45a0?, 0xc007d9e200?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebb938 sp=0xc034ebb8d8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebb9f8 sp=0xc034ebb938 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e200, {0x890100?, 0xc0000e42d0?, 0xc007d9e1c0?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebba58 sp=0xc034ebb9f8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebbb18 sp=0xc034ebba58 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e1c0, {0x890100?, 0xc0000e45a0?, 0xc007d9e180?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebbb78 sp=0xc034ebbb18 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebbc38 sp=0xc034ebbb78 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e180, {0x890100?, 0xc0000e42d0?, 0xc007d9e140?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebbc98 sp=0xc034ebbc38 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc034ebbd58 sp=0xc034ebbc98 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc007d9e140, {0x890100?, 0xc0000e45a0?, 0xc007d9e100?})
         encoding/gob/encode.go:546 +0x6e fp=0xc034ebbdb8 sp=0xc034ebbd58 pc=0x7610ee
 ...3728162 frames elided...
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb8198 sp=0xc054eb80d8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac0400, {0x890100?, 0xc0000e45a0?, 0xc000ac03c0?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb81f8 sp=0xc054eb8198 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb82b8 sp=0xc054eb81f8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac03c0, {0x890100?, 0xc0000e42d0?, 0x0?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb8318 sp=0xc054eb82b8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb83d8 sp=0xc054eb8318 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac0380, {0x890100?, 0xc0000e45a0?, 0xc000ac0340?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb8438 sp=0xc054eb83d8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb84f8 sp=0xc054eb8438 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac0340, {0x890100?, 0xc0000e42d0?, 0xc000ac0300?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb8558 sp=0xc054eb84f8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb8618 sp=0xc054eb8558 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac0300, {0x890100?, 0xc0000e45a0?, 0xc000ac02c0?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb8678 sp=0xc054eb8618 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb8738 sp=0xc054eb8678 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac02c0, {0x890100?, 0xc0000e42d0?, 0xc000ac0280?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb8798 sp=0xc054eb8738 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb8858 sp=0xc054eb8798 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac0280, {0x890100?, 0xc0000e45a0?, 0xc000ac0240?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb88b8 sp=0xc054eb8858 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb8978 sp=0xc054eb88b8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac0240, {0x890100?, 0xc0000e42d0?, 0xc000ac0200?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb89d8 sp=0xc054eb8978 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb8a98 sp=0xc054eb89d8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac0200, {0x890100?, 0xc0000e45a0?, 0xc000ac01c0?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb8af8 sp=0xc054eb8a98 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb8bb8 sp=0xc054eb8af8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac01c0, {0x890100?, 0xc0000e42d0?, 0xc000ac0100?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb8c18 sp=0xc054eb8bb8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb8cd8 sp=0xc054eb8c18 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac0180, {0x890100?, 0xc0000e45a0?, 0x7609ee?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb8d38 sp=0xc054eb8cd8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb8df8 sp=0xc054eb8d38 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac0140, {0x890100?, 0xc0000e42d0?, 0xc000b1f1e8?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb8e58 sp=0xc054eb8df8 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb8f18 sp=0xc054eb8e58 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac0100, {0x890100?, 0xc0000e45a0?, 0x0?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb8f78 sp=0xc054eb8f18 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e42d0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb9038 sp=0xc054eb8f78 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac00c0, {0x890100?, 0xc0000e42d0?, 0xc00004c258?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb9098 sp=0xc054eb9038 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0000e45a0?, 0x80ee20?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb9158 sp=0xc054eb9098 pc=0x75e6be
 encoding/gob.encOpFor.func4(0x890100?, 0xc000ac0080, {0x890100?, 0xc0000e45a0?, 0xc000b1f230?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb91b8 sp=0xc054eb9158 pc=0x7610ee
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00006dbc0, 0xc000abe168, {0x890100?, 0xc0001321b0?, 0x404bcb?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb9278 sp=0xc054eb91b8 pc=0x75e6be
 encoding/gob.(*Encoder).encode(0xc00013e1e0, 0xc00006dbc0, {0x80ee20?, 0xc0001321b0?, 0xc0000a1740?}, 0xc0000a1740)
         encoding/gob/encode.go:666 +0x1b0 fp=0xc054eb9318 sp=0xc054eb9278 pc=0x7624d0
 encoding/gob.(*Encoder).encodeInterface(0xc00013e1e0, 0xc00013e218, {0x829900?, 0xc000abe1b0?, 0x75cdd4?})
         encoding/gob/encode.go:419 +0x86b fp=0xc054eb9490 sp=0xc054eb9318 pc=0x75feeb
 encoding/gob.encOpFor.func5(0x85f620?, 0xc0000a1e40, {0x829900?, 0xc000abe1b0?, 0xc000b1f560?})
         encoding/gob/encode.go:554 +0xcf fp=0xc054eb94e8 sp=0xc054eb9490 pc=0x7681cf
 encoding/gob.(*Encoder).encodeStruct(0xc00013e1e0, 0xc00013e218, 0xc0000104c8, {0x85f620?, 0xc000abe1b0?, 0x0?})
         encoding/gob/encode.go:328 +0x2de fp=0xc054eb95a8 sp=0xc054eb94e8 pc=0x75e6be
 encoding/gob.encOpFor.func4(0xc000170901?, 0xc0000a1e00, {0x85f620?, 0xc000abe1b0?, 0x467573?})
         encoding/gob/encode.go:546 +0x6e fp=0xc054eb9608 sp=0xc054eb95a8 pc=0x7610ee
 encoding/gob.encodeReflectValue(0xc0000a1e00, {0x85f620?, 0xc000abe1b0?, 0xc000024aa0?}, 0xc0000232d0, 0xc0000a1f00?)
         encoding/gob/encode.go:363 +0x9c fp=0xc054eb9678 sp=0xc054eb9608 pc=0x75ef9c
 encoding/gob.(*Encoder).encodeMap(0xc00013e1e0, 0xc000134e40?, {0x832080?, 0xc0000a1708?, 0xc000b1f7f8?}, 0x8fcdc8, 0xc0000232d0, 0x0, 0x0)
         encoding/gob/encode.go:375 +0x538 fp=0xc054eb97b0 sp=0xc054eb9678 pc=0x75f598
 encoding/gob.encOpFor.func3(0x832080?, 0xc0000a1dc0, {0x832080?, 0xc0000a1708?, 0xc000134e10?})
         encoding/gob/encode.go:536 +0x12c fp=0xc054eb9848 sp=0xc054eb97b0 pc=0x76126c
 encoding/gob.(*Encoder).encodeSingle(0x8148e0?, 0xc0000a1708?, 0x97f148?, {0x832080?, 0xc0000a1708?, 0x404bcb?})
         encoding/gob/encode.go:301 +0x1fc fp=0xc054eb98d0 sp=0xc054eb9848 pc=0x75e2dc
 encoding/gob.(*Encoder).encode(0xc00013e1e0, 0xc00013e218, {0x8148e0?, 0xc0000a1708?, 0xc0000a1300?}, 0xc0000a1300)
         encoding/gob/encode.go:668 +0x1d3 fp=0xc054eb9970 sp=0xc054eb98d0 pc=0x7624f3
 encoding/gob.(*Encoder).EncodeValue(0xc00013e1e0, {0x8148e0?, 0xc0000a1708?, 0x80ee20?})
         encoding/gob/encoder.go:251 +0x405 fp=0xc054eb9a30 sp=0xc054eb9970 pc=0x763905
 encoding/gob.(*Encoder).Encode(0xc000b1fad0?, {0x8148e0?, 0xc0000a1708?})
         encoding/gob/encoder.go:176 +0x75 fp=0xc054eb9a70 sp=0xc054eb9a30 pc=0x763315
 github.com/patrickmn/go-cache.(*cache).Save(0xc0000a1700, {0x975160, 0xc00004c200})
         github.com/patrickmn/go-cache@v2.1.0+incompatible/cache.go:975 +0x2f4 fp=0xc054eb9b50 sp=0xc054eb9a70 pc=0x7b5834
 github.com/patrickmn/go-cache.(*cache).SaveFile(0xc0000a1700, {0x8b7991?, 0xc000b1fd18?})
         github.com/patrickmn/go-cache@v2.1.0+incompatible/cache.go:989 +0x54 fp=0xc054eb9b98 sp=0xc054eb9b50 pc=0x7b59f4
 github.com/Septrum101/apronLEDPanel/controller.(*Controller).saveCache(0xc00009c8a0)
         github.com/Septrum101/apronLEDPanel/controller/controller.go:297 +0x75f fp=0xc054eb9d88 sp=0xc054eb9b98 pc=0x7e3e3f
 github.com/Septrum101/apronLEDPanel/controller.(*Controller).Close(0xc00009c8a0)
         github.com/Septrum101/apronLEDPanel/controller/controller.go:258 +0x265 fp=0xc054eb9e98 sp=0xc054eb9d88 pc=0x7e3685
 main.main()
         ./main.go:58 +0x28b fp=0xc054eb9f50 sp=0xc054eb9e98 pc=0x7e852b
 runtime.main()
         runtime/proc.go:271 +0x29d fp=0xc054eb9fe0 sp=0xc054eb9f50 pc=0x43aafd
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc054eb9fe8 sp=0xc054eb9fe0 pc=0x46d1a1
 goroutine 2 gp=0xc000006700 m=nil [force gc (idle), 2 minutes]:
 runtime.gopark(0x61643916323e0?, 0x0?, 0x0?, 0x0?, 0x0?)
         runtime/proc.go:402 +0xce fp=0xc000048fa8 sp=0xc000048f88 pc=0x43af2e
 runtime.goparkunlock(...)
         runtime/proc.go:408
 runtime.forcegchelper()
         runtime/proc.go:326 +0xb3 fp=0xc000048fe0 sp=0xc000048fa8 pc=0x43adb3
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc000048fe8 sp=0xc000048fe0 pc=0x46d1a1
 created by runtime.init.6 in goroutine 1
         runtime/proc.go:314 +0x1a
 goroutine 3 gp=0xc000006c40 m=nil [GC sweep wait]:
 runtime.gopark(0x1?, 0x0?, 0x0?, 0x0?, 0x0?)
         runtime/proc.go:402 +0xce fp=0xc000049780 sp=0xc000049760 pc=0x43af2e
 runtime.goparkunlock(...)
         runtime/proc.go:408
 runtime.bgsweep(0xc000068000)
         runtime/mgcsweep.go:318 +0xdf fp=0xc0000497c8 sp=0xc000049780 pc=0x42693f
 runtime.gcenable.gowrap1()
         runtime/mgc.go:203 +0x25 fp=0xc0000497e0 sp=0xc0000497c8 pc=0x41b245
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc0000497e8 sp=0xc0000497e0 pc=0x46d1a1
 created by runtime.gcenable in goroutine 1
         runtime/mgc.go:203 +0x66
 goroutine 4 gp=0xc000006e00 m=nil [GC scavenge wait]:
 runtime.gopark(0x10000?, 0x96ff60?, 0x0?, 0x0?, 0x0?)
         runtime/proc.go:402 +0xce fp=0xc000049f78 sp=0xc000049f58 pc=0x43af2e
 runtime.goparkunlock(...)
         runtime/proc.go:408
 runtime.(*scavengerState).park(0xc42f80)
         runtime/mgcscavenge.go:425 +0x49 fp=0xc000049fa8 sp=0xc000049f78 pc=0x4242e9
 runtime.bgscavenge(0xc000068000)
         runtime/mgcscavenge.go:658 +0x59 fp=0xc000049fc8 sp=0xc000049fa8 pc=0x424899
 runtime.gcenable.gowrap2()
         runtime/mgc.go:204 +0x25 fp=0xc000049fe0 sp=0xc000049fc8 pc=0x41b1e5
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc000049fe8 sp=0xc000049fe0 pc=0x46d1a1
 created by runtime.gcenable in goroutine 1
         runtime/mgc.go:204 +0xa5
 goroutine 17 gp=0xc00009e000 m=nil [finalizer wait, 2 minutes]:
 runtime.gopark(0xc000048660?, 0x4237bc?, 0x80?, 0x54?, 0x550011?)
         runtime/proc.go:402 +0xce fp=0xc000048620 sp=0xc000048600 pc=0x43af2e
 runtime.runfinq()
         runtime/mfinal.go:194 +0x107 fp=0xc0000487e0 sp=0xc000048620 pc=0x41a287
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc0000487e8 sp=0xc0000487e0 pc=0x46d1a1
 created by runtime.createfing in goroutine 1
         runtime/mfinal.go:164 +0x3d
 goroutine 18 gp=0xc00009e700 m=nil [select, 2 minutes]:
 runtime.gopark(0xc000044790?, 0x2?, 0x68?, 0x46?, 0xc000044784?)
         runtime/proc.go:402 +0xce fp=0xc000044630 sp=0xc000044610 pc=0x43af2e
 runtime.selectgo(0xc000044790, 0xc000044780, 0x0?, 0x0, 0x0?, 0x1)
         runtime/select.go:327 +0x725 fp=0xc000044750 sp=0xc000044630 pc=0x44c2e5
 github.com/patrickmn/go-cache.(*janitor).Run(0xc000150320, 0xc0000a16c0)
         github.com/patrickmn/go-cache@v2.1.0+incompatible/cache.go:1079 +0x7d fp=0xc0000447c0 sp=0xc000044750 pc=0x7b621d
 github.com/patrickmn/go-cache.runJanitor.gowrap1()
         github.com/patrickmn/go-cache@v2.1.0+incompatible/cache.go:1099 +0x25 fp=0xc0000447e0 sp=0xc0000447c0 pc=0x7b63c5
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc0000447e8 sp=0xc0000447e0 pc=0x46d1a1
 created by github.com/patrickmn/go-cache.runJanitor in goroutine 1
         github.com/patrickmn/go-cache@v2.1.0+incompatible/cache.go:1099 +0xdb
 goroutine 19 gp=0xc00009e8c0 m=nil [select, 2 minutes]:
 runtime.gopark(0xc000044f90?, 0x2?, 0xc8?, 0x4e?, 0xc000044f84?)
         runtime/proc.go:402 +0xce fp=0xc000044e30 sp=0xc000044e10 pc=0x43af2e
 runtime.selectgo(0xc000044f90, 0xc000044f80, 0x0?, 0x0, 0x0?, 0x1)
         runtime/select.go:327 +0x725 fp=0xc000044f50 sp=0xc000044e30 pc=0x44c2e5
 github.com/patrickmn/go-cache.(*janitor).Run(0xc000150330, 0xc0000a1700)
         github.com/patrickmn/go-cache@v2.1.0+incompatible/cache.go:1079 +0x7d fp=0xc000044fc0 sp=0xc000044f50 pc=0x7b621d
 github.com/patrickmn/go-cache.runJanitor.gowrap1()
         github.com/patrickmn/go-cache@v2.1.0+incompatible/cache.go:1099 +0x25 fp=0xc000044fe0 sp=0xc000044fc0 pc=0x7b63c5
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc000044fe8 sp=0xc000044fe0 pc=0x46d1a1
 created by github.com/patrickmn/go-cache.runJanitor in goroutine 1
         github.com/patrickmn/go-cache@v2.1.0+incompatible/cache.go:1099 +0xdb
 goroutine 20 gp=0xc00009ea80 m=nil [GC worker (idle)]:
 runtime.gopark(0x61648a10bebd9?, 0x2?, 0x5?, 0x4a?, 0x0?)
         runtime/proc.go:402 +0xce fp=0xc000045750 sp=0xc000045730 pc=0x43af2e
 runtime.gcBgMarkWorker()
         runtime/mgc.go:1310 +0xe5 fp=0xc0000457e0 sp=0xc000045750 pc=0x41d325
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc0000457e8 sp=0xc0000457e0 pc=0x46d1a1
 created by runtime.gcBgMarkStartWorkers in goroutine 1
         runtime/mgc.go:1234 +0x1c
 goroutine 21 gp=0xc00009ec40 m=nil [GC worker (idle)]:
 runtime.gopark(0x61648a10beb76?, 0x2?, 0xa6?, 0x75?, 0x0?)
         runtime/proc.go:402 +0xce fp=0xc000045f50 sp=0xc000045f30 pc=0x43af2e
 runtime.gcBgMarkWorker()
         runtime/mgc.go:1310 +0xe5 fp=0xc000045fe0 sp=0xc000045f50 pc=0x41d325
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc000045fe8 sp=0xc000045fe0 pc=0x46d1a1
 created by runtime.gcBgMarkStartWorkers in goroutine 1
         runtime/mgc.go:1234 +0x1c
 goroutine 34 gp=0xc000007880 m=nil [semacquire, 2 minutes]:
 runtime.gopark(0x5?, 0xc0000906b8?, 0xe0?, 0xd0?, 0xc4ade0?)
         runtime/proc.go:402 +0xce fp=0xc000090658 sp=0xc000090638 pc=0x43af2e
 runtime.goparkunlock(...)
         runtime/proc.go:408
 runtime.semacquire1(0xc00009bbd8, 0x0, 0x1, 0x0, 0x12)
         runtime/sema.go:160 +0x225 fp=0xc0000906c0 sp=0xc000090658 pc=0x44d325
 sync.runtime_Semacquire(0xc0000ce348?)
         runtime/sema.go:62 +0x25 fp=0xc0000906f8 sp=0xc0000906c0 pc=0x4696a5
 sync.(*WaitGroup).Wait(0xc00009bb80?)
         sync/waitgroup.go:116 +0x48 fp=0xc000090720 sp=0xc0000906f8 pc=0x4779a8
 github.com/spf13/viper.(*Viper).WatchConfig.func1()
         github.com/spf13/viper@v1.18.2/viper.go:502 +0x337 fp=0xc0000907e0 sp=0xc000090720 pc=0x71da17
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc0000907e8 sp=0xc0000907e0 pc=0x46d1a1
 created by github.com/spf13/viper.(*Viper).WatchConfig in goroutine 1
         github.com/spf13/viper@v1.18.2/viper.go:442 +0x87
 goroutine 35 gp=0xc000007a40 m=nil [IO wait, 2 minutes]:
 runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0xb?)
         runtime/proc.go:402 +0xce fp=0xc0009c1ca8 sp=0xc0009c1c88 pc=0x43af2e
 runtime.netpollblock(0x47ac58?, 0x4055c6?, 0x0?)
         runtime/netpoll.go:573 +0xf7 fp=0xc0009c1ce0 sp=0xc0009c1ca8 pc=0x433d57
 internal/poll.runtime_pollWait(0x7619c3b925b8, 0x72)
         runtime/netpoll.go:345 +0x85 fp=0xc0009c1d00 sp=0xc0009c1ce0 pc=0x467ee5
 internal/poll.(*pollDesc).wait(0xc00009d080?, 0xc0009c1e3b?, 0x1)
         internal/poll/fd_poll_runtime.go:84 +0x27 fp=0xc0009c1d28 sp=0xc0009c1d00 pc=0x499a87
 internal/poll.(*pollDesc).waitRead(...)
         internal/poll/fd_poll_runtime.go:89
 internal/poll.(*FD).Read(0xc00009d080, {0xc0009c1e3b, 0x10000, 0x10000})
         internal/poll/fd_unix.go:164 +0x27a fp=0xc0009c1dc0 sp=0xc0009c1d28 pc=0x49a5da
 os.(*File).read(...)
         os/file_posix.go:29
 os.(*File).Read(0xc000086d58, {0xc0009c1e3b?, 0x0?, 0x0?})
         os/file.go:118 +0x52 fp=0xc0009c1e00 sp=0xc0009c1dc0 pc=0x49eb32
 github.com/fsnotify/fsnotify.(*Watcher).readEvents(0xc0000a1e80)
         github.com/fsnotify/fsnotify@v1.7.0/backend_inotify.go:483 +0xcf fp=0xc0009d1fc8 sp=0xc0009c1e00 pc=0x5189cf
 github.com/fsnotify/fsnotify.NewBufferedWatcher.gowrap1()
         github.com/fsnotify/fsnotify@v1.7.0/backend_inotify.go:270 +0x25 fp=0xc0009d1fe0 sp=0xc0009d1fc8 pc=0x518405
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc0009d1fe8 sp=0xc0009d1fe0 pc=0x46d1a1
 created by github.com/fsnotify/fsnotify.NewBufferedWatcher in goroutine 34
         github.com/fsnotify/fsnotify@v1.7.0/backend_inotify.go:270 +0x1c5
 goroutine 36 gp=0xc000007c00 m=nil [select, 2 minutes]:
 runtime.gopark(0xc000091768?, 0x2?, 0x0?, 0x0?, 0xc000091710?)
         runtime/proc.go:402 +0xce fp=0xc0000915b8 sp=0xc000091598 pc=0x43af2e
 runtime.selectgo(0xc000091768, 0xc00009170c, 0x0?, 0x0, 0x0?, 0x1)
         runtime/select.go:327 +0x725 fp=0xc0000916d8 sp=0xc0000915b8 pc=0x44c2e5
 github.com/spf13/viper.(*Viper).WatchConfig.func1.1()
         github.com/spf13/viper@v1.18.2/viper.go:465 +0xf9 fp=0xc0000917e0 sp=0xc0000916d8 pc=0x71db59
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc0000917e8 sp=0xc0000917e0 pc=0x46d1a1
 created by github.com/spf13/viper.(*Viper).WatchConfig.func1 in goroutine 34
         github.com/spf13/viper@v1.18.2/viper.go:463 +0x2f9
 goroutine 37 gp=0xc000007dc0 m=nil [select, 2 minutes, locked to thread]:
 runtime.gopark(0xc000091fa8?, 0x2?, 0xc9?, 0xb1?, 0xc000091f94?)
         runtime/proc.go:402 +0xce fp=0xc000091e38 sp=0xc000091e18 pc=0x43af2e
 runtime.selectgo(0xc000091fa8, 0xc000091f90, 0x0?, 0x0, 0x0?, 0x1)
         runtime/select.go:327 +0x725 fp=0xc000091f58 sp=0xc000091e38 pc=0x44c2e5
 runtime.ensureSigM.func1()
         runtime/signal_unix.go:1034 +0x19f fp=0xc000091fe0 sp=0xc000091f58 pc=0x464e5f
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc000091fe8 sp=0xc000091fe0 pc=0x46d1a1
 created by runtime.ensureSigM in goroutine 1
         runtime/signal_unix.go:1017 +0xc8
 goroutine 38 gp=0xc000078380 m=0 mp=0xc43fc0 [syscall]:
 runtime.notetsleepg(0xca4aa0, 0xffffffffffffffff)
         runtime/lock_futex.go:246 +0x29 fp=0xc00008a7a0 sp=0xc00008a778 pc=0x40cf49
 os/signal.signal_recv()
         runtime/sigqueue.go:152 +0x29 fp=0xc00008a7c0 sp=0xc00008a7a0 pc=0x469e09
 os/signal.loop()
         os/signal/signal_unix.go:23 +0x13 fp=0xc00008a7e0 sp=0xc00008a7c0 pc=0x4a7b53
 runtime.goexit({})
         runtime/asm_amd64.s:1695 +0x1 fp=0xc00008a7e8 sp=0xc00008a7e0 pc=0x46d1a1
 created by os/signal.Notify.func1.1 in goroutine 1
         os/signal/signal.go:151 +0x1f

What did you expect to see?

save to file success

@Septrum101
Copy link
Author

Septrum101 commented Apr 21, 2024

Below is the demo code. It cannot work.

package main

import (
	"encoding/gob"
	"fmt"
	"log"
	"os"
)

type Node struct {
	Val  int
	Prev *Node
	Next *Node
}

func main() {
	// Creating doubly linked list
	head := &Node{Val: 1}
	head.Next = &Node{Val: 2, Prev: head}
	head.Next.Next = &Node{Val: 3, Prev: head.Next}

	// Create and open file to store data
	file, err := os.Create("store.gob")
	if err != nil {
		log.Fatal("create file error:", err)
	}
	defer file.Close()

	// Create encoder and encode structure to file
	enc := gob.NewEncoder(file)
	if err = enc.Encode(head); err != nil {
		log.Fatal("encode error:", err)
	}

	// Close the file
	file.Close()

	// Open file to be ready for decoding
	file, err = os.Open("store.gob")
	if err != nil {
		log.Fatal("open file error:", err)
	}
	defer file.Close()

	// Create decoder and decode structure from file
	var decodedHead Node
	dec := gob.NewDecoder(file)
	if err = dec.Decode(&decodedHead); err != nil {
		log.Fatal("decode error:", err)
	}

	// Printing decoded data
	for node := &decodedHead; node != nil; node = node.Next {
		fmt.Println(node.Val)
	}
}

@Septrum101
Copy link
Author

The singly linked list works perfect.

package main

import (
	"encoding/gob"
	"fmt"
	"log"
	"os"
)

type Node struct {
	Val  int
	Next *Node
}

func main() {
	// Creating singly linked list
	head := &Node{Val: 1}
	head.Next = &Node{Val: 2}
	head.Next.Next = &Node{Val: 3}

	// Create and open file to store data
	file, err := os.Create("store.gob")
	if err != nil {
		log.Fatal("creation file error:", err)
	}
	defer file.Close()

	// Create encoder and encode structure to file
	enc := gob.NewEncoder(file)
	if err = enc.Encode(head); err != nil {
		log.Fatal("encoding error:", err)
	}

	// Close the file
	file.Close()

	// Open file for decoding
	file, err = os.Open("store.gob")
	if err != nil {
		log.Fatal("opening file error:", err)
	}
	defer file.Close()

	// Create decoder and decode structure from file
	var decodedHead Node
	dec := gob.NewDecoder(file)
	if err = dec.Decode(&decodedHead); err != nil {
		log.Fatal("decoding error:", err)
	}

	// Printing the decoded list
	for node := &decodedHead; node != nil; node = node.Next {
		fmt.Println(node.Val)
	}
}

@seankhliao
Copy link
Member

from the package docs

recursive values (data with cycles) are problematic.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 21, 2024
@Septrum101
Copy link
Author

thanks for your reply.

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