Skip to content

Commit f05cc00

Browse files
NH-2322 - reverting old fix which was just a crutch, now fixed through NH-4077.
1 parent df0f06f commit f05cc00

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/NHibernate/Async/Engine/ActionQueue.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ public Task AddActionAsync(BulkOperationCleanupAction cleanupAction, Cancellatio
4040
private async Task ExecuteActionsAsync(IList list, CancellationToken cancellationToken)
4141
{
4242
cancellationToken.ThrowIfCancellationRequested();
43-
int size = list.Count;
44-
for (int i = 0; i < size; i++)
45-
await (ExecuteAsync((IExecutable)list[i], cancellationToken)).ConfigureAwait(false);
43+
// Actions may raise events to which user code can react and cause changes to action list.
44+
// It will then fail here due to list being modified. (Some previous code was dodging the
45+
// trouble with a for loop which was not failing provided the list was not getting smaller.
46+
// But then it was clearing it without having executed added actions (if any), ...)
47+
foreach (IExecutable executable in list)
48+
await (ExecuteAsync(executable, cancellationToken)).ConfigureAwait(false);
4649

4750
list.Clear();
4851
await (session.Batcher.ExecuteBatchAsync(cancellationToken)).ConfigureAwait(false);

src/NHibernate/Engine/ActionQueue.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,12 @@ public void RegisterProcess(BeforeTransactionCompletionProcessDelegate process)
121121

122122
private void ExecuteActions(IList list)
123123
{
124-
int size = list.Count;
125-
for (int i = 0; i < size; i++)
126-
Execute((IExecutable)list[i]);
124+
// Actions may raise events to which user code can react and cause changes to action list.
125+
// It will then fail here due to list being modified. (Some previous code was dodging the
126+
// trouble with a for loop which was not failing provided the list was not getting smaller.
127+
// But then it was clearing it without having executed added actions (if any), ...)
128+
foreach (IExecutable executable in list)
129+
Execute(executable);
127130

128131
list.Clear();
129132
session.Batcher.ExecuteBatch();

0 commit comments

Comments
 (0)