goccy/go-graphviz

unexpected signal during runtime execution

rleungx opened this issue · 5 comments

When I use RenderFilename to generate a SVG, something happend:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x10 pc=0x4bedd62]

runtime stack:
runtime.throw(0x4f91d88, 0x2a)
	/.../.gvm/gos/go1.13.10/src/runtime/panic.go:774 +0x72
runtime.sigpanic()
	/.../.gvm/gos/go1.13.10/src/runtime/signal_unix.go:378 +0x47c

goroutine 801 [syscall]:
runtime.cgocall(0x4b9aab0, 0xc000541ba0, 0x3)
	/.../.gvm/gos/go1.13.10/src/runtime/cgocall.go:128 +0x5b fp=0xc000541b70 sp=0xc000541b38 pc=0x400588b
github.com/goccy/go-graphviz/internal/ccall._Cfunc_gvLayout(0x6613d80, 0x6615530, 0x653ac70, 0x0)
	_cgo_gotypes.go:2365 +0x4d fp=0xc000541ba0 sp=0xc000541b70 pc=0x48da6ad
github.com/goccy/go-graphviz/internal/ccall.GvLayout.func1(0xc000f25048, 0xc000f25058, 0x4f6278f, 0x3, 0x4070b0c)
	/.../.gvm/pkgsets/go1.13.10/global/pkg/mod/github.com/goccy/go-graphviz@v0.0.4/internal/ccall/gvc.go:736 +0xe7 fp=0xc000541bf0 sp=0xc000541ba0 pc=0x48ea547
github.com/goccy/go-graphviz/internal/ccall.GvLayout(0xc000f25048, 0xc000f25058, 0x4f6278f, 0x3, 0x4f39e00, 0xc0001520d0)
	/.../.gvm/pkgsets/go1.13.10/global/pkg/mod/github.com/goccy/go-graphviz@v0.0.4/internal/ccall/gvc.go:736 +0x49 fp=0xc000541c28 sp=0xc000541bf0 pc=0x48e5e29
github.com/goccy/go-graphviz/gvc.(*Context).Layout(...)
	/.../.gvm/pkgsets/go1.13.10/global/pkg/mod/github.com/goccy/go-graphviz@v0.0.4/gvc/gvc.go:29
github.com/goccy/go-graphviz.(*Graphviz).RenderFilename(0xc000c9a990, 0xc000f25060, 0x4f628f7, 0x3, 0xc0003c5ce0, 0x5f, 0x0, 0x0)
	/.../.gvm/pkgsets/go1.13.10/global/pkg/mod/github.com/goccy/go-graphviz@v0.0.4/graphviz.go:115 +0x73 fp=0xc000541cc0 sp=0xc000541c28 pc=0x4962243

It happened on my mac (v10.14.5)

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/.../Library/Caches/go-build"
GOENV="/.../Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/.../.gvm/pkgsets/go1.13.10/global"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/.../.gvm/gos/go1.13.10"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/.../.gvm/gos/go1.13.10/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/.../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 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hj/c7qldcv90n59k0bddyjm3mkw0000gn/T/go-build047072890=/tmp/go-build -gno-record-gcc-switches -fno-common"

Would you like to take a look?

goccy commented

Thanks for the reporting .
Could you provide a simple code to reproduce ?

It seems this library doesn't support handling the DOT files concurrently? We need to handle the concurrency by ourselves, am I right?

goccy commented

Oh... I hadn't considered rendering them in concurrency.
So, I'm going to fix it, but first of all, may I ask you to implement the concurrency on your own ?

lbe commented

I have also run into this concurrency issue. I have created a test program go-graphviz-test and documented my findings in the readme. I am very new to Go, but it appears that the Go integration with the graphviz C libraries use a pointer when calling graphviz.New() that is global to all goroutines. The only work around that I have found is to implement a sync.Mutex to block so that only one goroutine is actually working with graphviz at a time.

In my case, this eliminates any performance improvements over the non-concurrent implementation. My use case is to process ~20K flow network (digraph) definitions and generate SVGs for each of these. go tool pprof shows that the vast majority of the runtime is spent on RenderFilename.

Fortunately, the overall performance of the synchronous solution in Go is good and meets my needs at this time; however, as demands grow, I do expect to need a way to work this in a more parallel manner.

I hope that you will be able to provide support for concurrency.

Thank you! lbe

I'm running into this issue as well on go version 1.20.3 and go-graphviz v0.1.1.