Allocator appears to leak mmaped memory in certain situations
First off, thanks for maintaining this package - it's great to have a sqlite driver that doesn't depend on cgo!
We've been running this in one of our production services for a few weeks and we've noticed that over time the program leaks memory. After a bit of debugging it seems that the leak isn't coming from the heap, but from mmap calls made by this sqlite driver. The leak continues until the linux oom killer steps in to kill it.
The leak seems to occur when several goroutines query a sqlite database, and at least one of them is querying for a record that does not exist. I've created a minimal testcase that demonstrates the leak on linux (I've been running it on ubuntu 16.04, AMD64).
The testcase can be started using make debug
, and the leak in allocations observed using make pmap
. You can comment in/out the lines that contain does not exist
to see how the behaviour changes when all of the queries succeed. There's an example breakpoint in the README that will pause execution in the mmap allocator when the driver starts to leak allocations. It seems that querying from several concurrent goroutines is also important for recreating the leak - when I lower the concurrency to 1 the script does not leak, so I presume the contention from several different goroutines is important...
I've tried to dig through this package to work out why allocations are not being deallocated, but unfortunately I'm not familiar enough with the sqlite source code to understand all the pointer dereferencing during query execution. I figured it might be worth opening this issue to see if you had any ideas about what might be going on.