goutil icon indicating copy to clipboard operation
goutil copied to clipboard

Concurrency issues in Dumper

Open pseudocodes opened this issue 3 years ago • 2 comments

System (please complete the following information):

  • OS: linux, macOS
  • GO Version: 1.18
  • Pkg Version: 0.5.5

Describe the bug

&fatal error: concurrent map read and map write


To see all goroutines, visit https://github.com/maruel/panicparse#gotraceback

1: running
    runtime :0 throw()
runtime.throw({0x10490cd05, 0x21})
        /usr/local/go/src/runtime/panic.go:1198 +0x54 fp=0x140003dfa70 sp=0x140003dfa40 pc=0x1046d9c34
runtime.mapaccess2(0x104997d80, 0x1400044c3f0, 0x140003dfaf0)
        /usr/local/go/src/runtime/map.go:469 +0x228 fp=0x140003dfab0 sp=0x140003dfa70 pc=0x1046b31f8
github.com/gookit/goutil/dump.(*Dumper).checkCyclicRef(0x14000146180, {0x1049f0bd0, 0x1049d2980}, {0x1049d2980, 0x14000384420, 0x199})
        /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:403 +0x6c fp=0x140003dfb30 sp=0x140003dfab0 pc=0x1047c8bcc
github.com/gookit/goutil/dump.(*Dumper).printRValue(0x14000146180, {0x1049f0bd0, 0x10497f860}, {0x10497f860, 0x14000384420, 0x16})
        /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:309 +0x121c fp=0x140003dfeb0 sp=0x140003dfb30 pc=0x1047c799c
github.com/gookit/goutil/dump.(*Dumper).printOne(0x14000146180, {0x10497f860, 0x14000384420})
        /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:229 +0x118 fp=0x140003dff30 sp=0x140003dfeb0 pc=0x1047c6718
github.com/gookit/goutil/dump.(*Dumper).dump(0x14000146180, {0x140003dffa8, 0x1, 0x1})
        /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:171 +0x120 fp=0x140003dff80 sp=0x140003dff30 pc=0x1047c5e20
github.com/gookit/goutil/dump.(*Dumper).Println(...)
        /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dumper.go:136
github.com/gookit/goutil/dump.Println(...)
        /{$GOPATH}/pkg/mod/github.com/gookit/[email protected]/dump/dump.go:96
main.(*SimpleTradeSpi).OnRtnTrade(0x104bdd850, 0x14000384420)
        /{$GOPATH}/sample/main.go:274 +0x5c fp=0x140003dffc0 sp=0x140003dff80 pc=0x10490021c
runtime.goexit()
        /usr/local/go/src/runtime/asm_arm64.s:1133 +Failed: failed to parse int on line: "runtime.throw({0x10490cd05, 0x21})"

出错位置:

func (d *Dumper) checkCyclicRef(t reflect.Type, v reflect.Value) (goon bool) {
	addr := v.UnsafeAddr()
	vis := visit{addr, t}

	if vd, ok := d.visited[vis]; ok && vd < d.MaxDepth { <------- here
		d.indentPrint(t.String(), "{(!CYCLIC REFERENCE!)}\n")
		return false // don't print v again
	}

	// record
	d.visited[vis] = d.curDepth
	return true
}

pseudocodes avatar Jul 04 '22 05:07 pseudocodes

why not use sync.Map

pseudocodes avatar Jul 06 '22 05:07 pseudocodes

sync.Map is too heavy

inhere avatar Jul 06 '22 07:07 inhere

fixed on v0.5.6+

inhere avatar Sep 03 '22 06:09 inhere