Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2435 Transactions are not removed in LiteDB 5.0.18 #2436

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions LiteDB/Engine/Query/QueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ internal BsonDataReader ExecuteQuery(bool executionPlan)
return new BsonDataReader(RunQuery(), _collection, _state);

IEnumerable<BsonDocument> RunQuery()
{
try
{
var snapshot = transaction.CreateSnapshot(_query.ForUpdate ? LockMode.Write : LockMode.Read, _collection, false);

Expand All @@ -86,14 +88,6 @@ IEnumerable<BsonDocument> RunQuery()
{
yield return _query.Select.ExecuteScalar(_pragmas.Collation).AsDocument;
}

transaction.OpenCursors.Remove(_cursor);

if (isNew)
{
_monitor.ReleaseTransaction(transaction);
}

yield break;
}

Expand All @@ -108,14 +102,6 @@ IEnumerable<BsonDocument> RunQuery()
if (executionPlan)
{
yield return queryPlan.GetExecutionPlan();

transaction.OpenCursors.Remove(_cursor);

if (isNew)
{
_monitor.ReleaseTransaction(transaction);
}

yield break;
}

Expand All @@ -128,6 +114,8 @@ IEnumerable<BsonDocument> RunQuery()
// start cursor elapsed timer
_cursor.Elapsed.Start();

try
{
using (var enumerator = pipe.Pipe(nodes, queryPlan).GetEnumerator())
{
var read = false;
Expand Down Expand Up @@ -164,16 +152,22 @@ IEnumerable<BsonDocument> RunQuery()
}
}
}

}
finally
{
// stop cursor elapsed
_cursor.Elapsed.Stop();

}
}
finally
{
transaction.OpenCursors.Remove(_cursor);

if (isNew)
{
_monitor.ReleaseTransaction(transaction);
}
}
};
}

Expand Down