-
Notifications
You must be signed in to change notification settings - Fork 79
cgo runtime panic #8
Comments
Environment: uname -a
Darwin johns-mbp.home 13.2.0 Darwin Kernel Version 13.2.0: Thu Apr 17 23:03:13 PDT 2014; root:xnu-2422.100.13~1/RELEASE_X86_64 x86_64 |
Looks like it is being caused by |
I can't recreate this, though I only have go 1.4 and the development version (pre-1.5) installed at the moment. Looks like it might be a race condition with the finalizers being called during a gc. |
And now I am able to recreate it using the |
Hello, I observed the same problem, on very similar code: shape, _ := geos.FromWKT(wkt)
box, _ := shape.Envelope()
boundingLine, _ := box.Shell()
geosCoordinates, _ := boundingLine.Coords()
for _, val := range geosCoordinates {
coordinates = append(coordinates, s2.LatLngFromDegrees(val.X, val.Y))
} Which produces SIGSEGV under heavy load (10 goroutines, database queries, millions of WKT strings). The typical stacktrace was:
As far as I can tell it is an attempt to dereference invalid pointer in C function GEOSCoordSeq_getY_r. Sometimes it was from GEOSCoordSeq_getX_r, several errors were from 'size'-functions. But it is always pointer dereference problem during geos.Coords() call. As otherwise structures are correct (and I can't reproduce bug if no concurrency involved) my guess was garbage collector, which comes in between calls to geos.FromWKT(wkt)/shape.Envelope()/box.Shell()/boundingLine.Coords() and frees geometries involved in geos.Coords() computations. To workaround the problem I added silly code to hold variables until after geos.Coords() geosCoordinates, _ := boundingLine.Coords()
if nil != err {
log.Printf("%d %d %d", shape, box, boundingLine)
} Surprisingly this worked well. However I would like to see a correct solution to the pointer ownership problem. |
The problem is twofold: - In Geometry.Coords() we have to make sure the parent Geometry outlives the processing of the coordinates array. - The previous condition is not enough when the geometry comes from Shell() or Holes(), which return internal objects. We have to make sure the shell/hole parent geometry outlives the shell/hole instance. The fix is similar to the one suggested in paulsmith#11. There are probably a lot of places where either previous conditions are required, I have not checked all the code. Note: this change the minimum required Go version to 1.7. I tried to play build tag games to have empty versions of the runtime.KeepAlive call, and failed. Fixes paulsmith#8
The problem is twofold: - In Geometry.Coords() we have to make sure the parent Geometry outlives the processing of the coordinates array. - The previous condition is not enough when the geometry comes from Shell() or Holes(), which return internal objects. We have to make sure the shell/hole parent geometry outlives the shell/hole instance. The fix is similar to the one suggested in paulsmith#11. There are probably a lot of places where either previous conditions are required, I have not checked all the code. Note: this change the minimum required Go version to 1.7. I tried to play build tag games to have empty versions of the runtime.KeepAlive call, and failed. Fixes paulsmith#8 per -> pmezard
Under heavy load gogoes/cgo randomly panics and outputs
panic: runtime error: invalid memory address or nil pointer dereference
. I can't tell if this is in gogeos or cgo, so I though I'd report it here first.go version go1.3rc1 darwin/amd64
Code to reproduce:
Stack (line 17 is
x, _ := point.X()
):The text was updated successfully, but these errors were encountered: