Skip to content

Commit b55f050

Browse files
committed
More care on the finalizer path for database cleanup
1 parent f59785f commit b55f050

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/LightningDB/LightningDatabase.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal LightningDatabase(string name, LightningTransaction transaction, Databa
6161
/// Environment in which the database was opened.
6262
/// </summary>
6363
public LightningEnvironment Environment { get; }
64-
64+
6565
/// <summary>
6666
/// Gets the flags used when opening this database.
6767
/// </summary>
@@ -71,11 +71,11 @@ public DatabaseOpenFlags GetFlags(LightningTransaction transaction)
7171
{
7272
if (transaction == null)
7373
throw new ArgumentNullException(nameof(transaction));
74-
74+
7575
mdb_dbi_flags(transaction._handle, _handle, out var flags).ThrowOnError();
7676
return (DatabaseOpenFlags)flags;
7777
}
78-
78+
7979
/// <summary>
8080
/// Drops the database.
8181
/// </summary>
@@ -106,13 +106,13 @@ private void Dispose(bool disposing)
106106
_disposed = true;
107107
if (!IsOpened)
108108
return;
109-
if (!Environment.IsOpened)
109+
if (!Environment.IsOpened && _closeOnDispose && disposing)
110110
throw new InvalidOperationException("A database must be disposed before closing the environment");
111111

112112
IsOpened = false;
113113
_pinnedConfig?.Dispose();
114114

115-
if (_closeOnDispose)
115+
if (_closeOnDispose && Environment.IsOpened)
116116
mdb_dbi_close(Environment._handle, _handle);
117117

118118
if (disposing)
@@ -132,4 +132,4 @@ public void Dispose()
132132
{
133133
Dispose(false);
134134
}
135-
}
135+
}

0 commit comments

Comments
 (0)