Skip to content

Commit e8288a5

Browse files
bahusoidhazzik
authored andcommitted
Do not call GC.SuppressFinalize from finalizer thread
1 parent b3cdf05 commit e8288a5

File tree

8 files changed

+30
-25
lines changed

8 files changed

+30
-25
lines changed

src/NHibernate/AdoNet/AbstractBatcher.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,13 +616,13 @@ protected virtual void Dispose(bool isDisposing)
616616
if (isDisposing)
617617
{
618618
CloseCommands();
619+
// nothing for Finalizer to do - so tell the GC to ignore it
620+
GC.SuppressFinalize(this);
619621
}
620622

621623
// free unmanaged resources here
622624

623625
_isAlreadyDisposed = true;
624-
// nothing for Finalizer to do - so tell the GC to ignore it
625-
GC.SuppressFinalize(this);
626626
}
627627

628628
#endregion

src/NHibernate/Async/Transaction/AdoTransaction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ protected virtual async Task DisposeAsync(bool isDisposing, CancellationToken ca
181181
// Assume we are rolled back
182182
await (AfterTransactionCompletionAsync(false, cancellationToken)).ConfigureAwait(false);
183183
}
184+
// nothing for Finalizer to do - so tell the GC to ignore it
185+
GC.SuppressFinalize(this);
184186
}
185187

186188
// free unmanaged resources here
187189

188190
_isAlreadyDisposed = true;
189-
// nothing for Finalizer to do - so tell the GC to ignore it
190-
GC.SuppressFinalize(this);
191191
}
192192
}
193193

src/NHibernate/Connection/ConnectionProvider.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ protected virtual void Dispose(bool isDisposing)
198198
if (isDisposing)
199199
{
200200
log.Debug("Disposing of ConnectionProvider.");
201+
// nothing for Finalizer to do - so tell the GC to ignore it
202+
GC.SuppressFinalize(this);
201203
}
202204

203205
// free unmanaged resources here
204206

205207
_isAlreadyDisposed = true;
206-
// nothing for Finalizer to do - so tell the GC to ignore it
207-
GC.SuppressFinalize(this);
208208
}
209209

210210
#endregion

src/NHibernate/Impl/EnumerableImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,13 @@ protected virtual void Dispose(bool isDisposing)
310310
_currentResult = null;
311311
_session.Batcher.CloseCommand(_cmd, _reader);
312312
}
313+
// nothing for Finalizer to do - so tell the GC to ignore it
314+
GC.SuppressFinalize(this);
313315
}
314316

315317
// free unmanaged resources here
316318

317319
_isAlreadyDisposed = true;
318-
// nothing for Finalizer to do - so tell the GC to ignore it
319-
GC.SuppressFinalize(this);
320320
}
321321

322322
#endregion

src/NHibernate/Impl/SessionImpl.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,17 +1543,18 @@ private void Dispose(bool isDisposing)
15431543

15441544
// free managed resources that are being managed by the session if we
15451545
// know this call came through Dispose()
1546-
if (isDisposing && !IsClosed)
1546+
if (isDisposing)
15471547
{
1548-
Close();
1548+
if (!IsClosed)
1549+
{
1550+
Close();
1551+
}
1552+
// nothing for Finalizer to do - so tell the GC to ignore it
1553+
GC.SuppressFinalize(this);
15491554
}
15501555

15511556
// free unmanaged resources here
1552-
15531557
IsAlreadyDisposed = true;
1554-
1555-
// nothing for Finalizer to do - so tell the GC to ignore it
1556-
GC.SuppressFinalize(this);
15571558
}
15581559
}
15591560

src/NHibernate/Impl/StatelessSessionImpl.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,16 +812,19 @@ protected void Dispose(bool isDisposing)
812812

813813
// free managed resources that are being managed by the session if we
814814
// know this call came through Dispose()
815-
if (isDisposing && !IsClosed)
815+
if (isDisposing)
816816
{
817-
Close();
817+
if (!IsClosed)
818+
{
819+
Close();
820+
}
821+
822+
// nothing for Finalizer to do - so tell the GC to ignore it
823+
GC.SuppressFinalize(this);
818824
}
819825

820826
// free unmanaged resources here
821-
822827
_isAlreadyDisposed = true;
823-
// nothing for Finalizer to do - so tell the GC to ignore it
824-
GC.SuppressFinalize(this);
825828
}
826829
_context?.Dispose();
827830
}

src/NHibernate/Transaction/AdoTransaction.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,13 @@ protected virtual void Dispose(bool isDisposing)
387387
// Assume we are rolled back
388388
AfterTransactionCompletion(false);
389389
}
390+
// nothing for Finalizer to do - so tell the GC to ignore it
391+
GC.SuppressFinalize(this);
390392
}
391393

392394
// free unmanaged resources here
393395

394396
_isAlreadyDisposed = true;
395-
// nothing for Finalizer to do - so tell the GC to ignore it
396-
GC.SuppressFinalize(this);
397397
}
398398
}
399399

src/NHibernate/Util/JoinedEnumerable.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ private void Dispose(bool isDisposing)
159159
currentDisposable.Dispose();
160160
}
161161
}
162+
// nothing for Finalizer to do - so tell the GC to ignore it
163+
GC.SuppressFinalize(this);
162164
}
163165

164166
// free unmanaged resources here
165167

166168
_isAlreadyDisposed = true;
167-
// nothing for Finalizer to do - so tell the GC to ignore it
168-
GC.SuppressFinalize(this);
169169
}
170170

171171
#endregion
@@ -241,17 +241,18 @@ T IEnumerator<T>.Current
241241
public void Dispose()
242242
{
243243
Dispose(true);
244-
GC.SuppressFinalize(this);
245244
}
246245

247246
private void Dispose(bool disposing)
248247
{
249248
if (!disposed)
250249
{
251250
if (disposing)
251+
{
252252
for (; currentEnumIdx < enumerators.Length; currentEnumIdx++)
253253
enumerators[currentEnumIdx].Dispose();
254-
GC.SuppressFinalize(this);
254+
GC.SuppressFinalize(this);
255+
}
255256
disposed = true;
256257
}
257258
}

0 commit comments

Comments
 (0)