Greg Carter, on Fri Apr 27, wrote:
We recently upgraded to 1.0.80.0 from 1.0.77.0 and have found when we turn
connection pooling on we get seemingly random memory access violations that
happen in calls to UnsafeNativeMethods.sqlite3_busy_timeout ,call stack -
Open/SetTimeout (line 259 of SQLite3.cs).

After compiling SQLite debug what I have seen is that if the
SQLiteConnection object was disposed of by the garbage collector then the
object left in the pool has an invalid _sql pointer.  If the
SQLiteConnection is disposed explicitly such as at the end of a using
statement everything seems to work.

[Valiant and likely perspicacious diagnostic gleanings cut for space.]

... then fails with memory
access violation as the _sql pointer is no longer valid.

In the cases where everything works as it should I see a clear stack trace
back to my code where the connection is disposed of at the end of a using
when it is added to the pool.  It's when we have connections that are
disposed of as a result of garbage collection that things go wrong.

When you use a collection of native code from managed code, and when that native code has cleanup to do, defined by its own conventions rather than the conventions established for the managed code system, you cannot count on garbage collection to get the job done. In addition to memory allocations, there are likely to be on-disk data and files that need to be brought to a proper state when SQLite's designed close/exit mechanisms are invoked. You "works as it should" is only assured (inasmuch as any software can) when you use the .Net framework's assured disposition mechanism ("using ..." and properly implemented IDispose) or effect the equivalent in your own code.

So is this intended behaviour or a bug?  I can try to come up with a test
case that reproduces this if needed.

It's not really intended behavior but intent cannot cure this problem unless SQLite's finalizing API is used.

Thanks
Greg.
...
Best regards,
--
Larry Brasfield
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to