Bug 2915 - Sqlite file descriptor leak
Summary: Sqlite file descriptor leak
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Data.Sqlite ()
Version: 2.10.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-01-16 14:04 UTC by David Knight
Modified: 2013-04-23 10:07 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description David Knight 2012-01-16 14:04:48 UTC
I'm experiencing a problem with file descriptors leaking despite disposing of commands and connections.

I can reproduce this with the sample code in the mono touch docs (running it under macosx, not the iOS simulator or an iOS device) at http://docs.xamarin.com/ios/advanced_topics/system.data#Mono.Data.Sqlite 

After running that code, but before exiting if I run lsof I see 5 open file descriptors on the database.

Modifying the code so that the connection is disposed (via a using) doesn't change anything.

Adding pooling=false to the connection string doesn't change anything.
Comment 1 Justin Hill 2012-07-18 13:47:23 UTC
I noticed this, too, and would like to offer some additional information.  An exception summary from my application seems to indicate that there is an exception thrown in Mono.Data.Sqlite.SqliteConnection:Close() which is probably causing this issue.

3 throws from:
                Mono.Data.Sqlite.SqliteConnection:Close ()
                Mono.Data.Sqlite.SQLite3:Close ()
                System.Runtime.InteropServices.CriticalHandle:Dispose ()
                System.Runtime.InteropServices.CriticalHandle:Dispose (bool)
                Mono.Data.Sqlite.SqliteConnectionHandle:ReleaseHandle ()
                Mono.Data.Sqlite.SQLiteBase:CloseConnection (Mono.Data.Sqlite.SqliteConnectionHandle)
Comment 2 Justin Hill 2012-07-18 13:48:52 UTC
Or rather from SQLiteBase:CloseConnection.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2013-04-23 10:07:18 UTC
If you look at the exception, you'll see this message:

Mono.Data.Sqlite.SqliteException The database file is locked, unable to close due to unfinalised statements

this happens because the connection is closed before the command using the connection is disposed.

The sample code has been fixed to close the connection after disposing the command.