paulsmith / gogeos

Go library for spatial data operations and geometric algorithms (Go bindings for GEOS)
http://paulsmith.github.io/gogeos/
MIT License
280 stars 79 forks source link

libc++abi.dylib: Pure virtual function called #32

Open missinglink opened 2 years ago

missinglink commented 2 years ago

Hi,

Using this library under heavy load I received the following error. Any info about the meaning of "Pure virtual function called" or hints on where to look in the code to fix this much appreciated 🙏

libc++abi.dylib: Pure virtual function called!
SIGABRT: abort
PC=0x7fff7391f33a m=10 sigcode=0

goroutine 0 [idle]:
runtime: unknown pc 0x7fff7391f33a
stack: frame={sp:0x700006ac0b78, fp:0x0} stack=[0x700006a41350,0x700006ac0f50)
0000700006ac0a78:  00007fff9a0b4920  0000000000000000
0000700006ac0a88:  00007fff9a0b4920  0000000000000c03
0000700006ac0a98:  00007fff9a0b4918  0000700006ac0ac0
0000700006ac0aa8:  0000700006ac0ae0  00007fff9a0b4920
0000700006ac0ab8:  0000000000000000  0000000032aaaba2
0000700006ac0ac8:  0000000000000000  0000000000000000
0000700006ac0ad8:  0000700006ac0c10  0000000000000000
0000700006ac0ae8:  0000000032aaaba2  0000000000000000
0000700006ac0af8:  0000000000000000  0000000000000000
0000700006ac0b08:  0000000000000000  0000000000000000
0000700006ac0b18:  0000000000000000  0000000000000000
0000700006ac0b28:  0000000000000003  0000000000000000
0000700006ac0b38:  0000000000000000  00007fff9a0b4ec0
0000700006ac0b48:  00007fff9a0b4930  00007fff73860065
0000700006ac0b58:  0000000000000000  0000700006ac0ba0
0000700006ac0b68:  00007fff738628ed  0000000000000000
0000700006ac0b78: <00007fff739dbe60  0000000000000003
0000700006ac0b88:  0000700006ac0d20  0000700006ac0bc0
0000700006ac0b98:  00007fff9a0b5620  0000700006ac0be0
0000700006ac0ba8:  00007fff738a6808  e509fd3029420036
0000700006ac0bb8:  0000700006ac0ce0  00007000fffff9df
0000700006ac0bc8:  ffffffff00000008  0000700006ac0ce0
0000700006ac0bd8:  00007fff70b08f23  0000700006ac0d10
0000700006ac0be8:  00007fff70b05458  0000003000000008
0000700006ac0bf8:  0000700006ac0d20  0000700006ac0c30
0000700006ac0c08:  000000000de48450  0000003000000008
0000700006ac0c18:  0000700006ac0d20  0000700006ac0c30
0000700006ac0c28:  00007fff7399303c  00000000000000b7
0000700006ac0c38:  000000002ff087c0  0000700006ac0d60
0000700006ac0c48:  00000000046f81e8  000000c000001500
0000700006ac0c58:  0000000000000000  00000000048d1600
0000700006ac0c68:  000000000de48330  0000000000000070
runtime: unknown pc 0x7fff7391f33a
stack: frame={sp:0x700006ac0b78, fp:0x0} stack=[0x700006a41350,0x700006ac0f50)
0000700006ac0a78:  00007fff9a0b4920  0000000000000000
0000700006ac0a88:  00007fff9a0b4920  0000000000000c03
0000700006ac0a98:  00007fff9a0b4918  0000700006ac0ac0
0000700006ac0aa8:  0000700006ac0ae0  00007fff9a0b4920
0000700006ac0ab8:  0000000000000000  0000000032aaaba2
0000700006ac0ac8:  0000000000000000  0000000000000000
0000700006ac0ad8:  0000700006ac0c10  0000000000000000
0000700006ac0ae8:  0000000032aaaba2  0000000000000000
0000700006ac0af8:  0000000000000000  0000000000000000
0000700006ac0b08:  0000000000000000  0000000000000000
0000700006ac0b18:  0000000000000000  0000000000000000
0000700006ac0b28:  0000000000000003  0000000000000000
0000700006ac0b38:  0000000000000000  00007fff9a0b4ec0
0000700006ac0b48:  00007fff9a0b4930  00007fff73860065
0000700006ac0b58:  0000000000000000  0000700006ac0ba0
0000700006ac0b68:  00007fff738628ed  0000000000000000
0000700006ac0b78: <00007fff739dbe60  0000000000000003
0000700006ac0b88:  0000700006ac0d20  0000700006ac0bc0
0000700006ac0b98:  00007fff9a0b5620  0000700006ac0be0
0000700006ac0ba8:  00007fff738a6808  e509fd3029420036
0000700006ac0bb8:  0000700006ac0ce0  00007000fffff9df
0000700006ac0bc8:  ffffffff00000008  0000700006ac0ce0
0000700006ac0bd8:  00007fff70b08f23  0000700006ac0d10
0000700006ac0be8:  00007fff70b05458  0000003000000008
0000700006ac0bf8:  0000700006ac0d20  0000700006ac0c30
0000700006ac0c08:  000000000de48450  0000003000000008
0000700006ac0c18:  0000700006ac0d20  0000700006ac0c30
0000700006ac0c28:  00007fff7399303c  00000000000000b7
0000700006ac0c38:  000000002ff087c0  0000700006ac0d60
0000700006ac0c48:  00000000046f81e8  000000c000001500
0000700006ac0c58:  0000000000000000  00000000048d1600
0000700006ac0c68:  000000000de48330  0000000000000070

goroutine 5 [syscall]:
runtime.cgocall(0x4260d60, 0xc0003d9ce0, 0xc0003d9d00)
    /usr/local/opt/go/libexec/src/runtime/cgocall.go:154 +0x5b fp=0xc0003d9cb0 sp=0xc0003d9c78 pc=0x400483b
github.com/paulsmith/gogeos/geos._Cfunc_GEOSWKBWriter_write_r(0xc008200, 0x2ff08c00, 0x2ff087c0, 0xc0003f26d0, 0x0)
    _cgo_gotypes.go:2221 +0x49 fp=0xc0003d9ce0 sp=0xc0003d9cb0 pc=0x418dfa9
github.com/paulsmith/gogeos/geos.cGEOSWKBWriter_write.func1(0x2ff08c00, 0x2ff087c0, 0xc0003f26d0, 0x8)
    /code/go/pkg/mod/github.com/paulsmith/gogeos@v0.1.2/geos/cwrappers.go:961 +0xc9 fp=0xc0003d9d20 sp=0xc0003d9ce0 pc=0x419e4e9
github.com/paulsmith/gogeos/geos.cGEOSWKBWriter_write(0x2ff08c00, 0x2ff087c0, 0xc0003f26d0, 0x0)
    /code/go/pkg/mod/github.com/paulsmith/gogeos@v0.1.2/geos/cwrappers.go:961 +0x8f fp=0xc0003d9d68 sp=0xc0003d9d20 pc=0x419434f
github.com/paulsmith/gogeos/geos.encodeWkb(0xc0003f26c8, 0xc0003f2680, 0x441d048, 0x0, 0x0, 0x0, 0x0, 0x0)
    /code/go/pkg/mod/github.com/paulsmith/gogeos@v0.1.2/geos/wkb.go:67 +0xa2 fp=0xc0003d9df0 sp=0xc0003d9d68 pc=0x4199382
github.com/paulsmith/gogeos/geos.(*wkbEncoder).encode(...)
    /code/go/pkg/mod/github.com/paulsmith/gogeos@v0.1.2/geos/wkb.go:83
github.com/paulsmith/gogeos/geos.(*Geometry).WKB(0xc0003f2680, 0x4408448, 0x6, 0x441cf30, 0xc0003f2650, 0x0)
    /code/go/pkg/mod/github.com/paulsmith/gogeos@v0.1.2/geos/geom.go:95 +0x45 fp=0xc0003d9e40 sp=0xc0003d9df0 pc=0x41946c5
...
uname -a
Darwin Peters-MacBook-Pro-2.local 19.6.0 Darwin Kernel Version 19.6.0: Thu Jun 18 20:49:00 PDT 2020; root:xnu-6153.141.1~1/RELEASE_X86_64 x86_64
grep paulsmith go.mod
    github.com/paulsmith/gogeos v0.1.2 // indirect
head $(brew --prefix geos)/ChangeLog
2021-02-10  Paul Ramsey <pramsey@cleverelephant.ca>

    * NEWS: Update NEWS for 3.9.1

2021-02-09  Paul Ramsey <pramsey@cleverelephant.ca>

    Merge branch '3.9' of https://git.osgeo.org/gitea/geos/geos into
    3.9

2021-02-09  Paul Ramsey <pramsey@cleverelephant.ca>

possibly related: https://github.com/paulsmith/gogeos/pull/29

missinglink commented 2 years ago

This was caused by passing a reference to another go routine via a chan *geos.Geometry. Refactoring the code to do all operations within the scope of a single function avoided the issue.

After playing with the lib a little more it seems that it's not thread-safe. Does anyone know if that's the case? I noticed a few years ago that spatialite migrated from GEOS to RTTOPO because it offered improved thread-safety.