System.Data.SQLite
View Ticket
Not logged in
Ticket UUID: 6c6ecccc5f8c5c6cf2409ad57bde3bfeef78fc01
Title: access violation with CommandBehavior.CloseConnection
Status: Closed Type: Code_Defect
Severity: Critical Priority: NextRelease
Subsystem: Integration_Via_PInvoke Resolution: Fixed
Last Modified: 2012-10-26 00:59:34
Version Found In: 1.0.82.0
Description:
There appears to be an issue with SQLiteDataReader and its use of the CommandBehavior.CloseConnection flag that can cause an access violation on the GC thread for the underlying statement handle.

mistachkin added on 2012-10-26 00:27:10 UTC:

Test case for this ticket is here: [4960a565c2].


mistachkin added on 2012-10-26 00:44:50 UTC:

The root cause of this issue was the combination of:

1. Using the new sqlite3_close_v2() public API, introduced in 1.0.82.0.

2. Using an extension, such as FTS, that prepares its own statements and finalizes them upon xDisconnect being called on its virtual table.

3. The connection being closed prior to the statement being finalized, in this case through the usage of the CommandBehavior.CloseConnection flag to the SQLiteCommand.ExecuteReader method.

When all of the above conditions were met, the sqlite3_finalize() API ended up being reentrant and freeing the memory used by the connection prematurely, leading to an assert in the DEBUG build.

This issue has been fixed in the SQLite core library and the fix will be present in the next release version of System.Data.SQLite. In the meantime, to work around this issue, avoid using the CommandBehavior.CloseConnection flag and make sure that all SQLiteDataReader and SQLiteCommand objects are disposed prior to disposing or closing the connection associated with them.


mistachkin added on 2012-10-26 00:59:34 UTC:
Fixed in SQLite trunk by check-in 6d42d806ad.
Fixed in System.Data.SQLite trunk by check-in [e702fa192f].