-
Notifications
You must be signed in to change notification settings - Fork 933
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 concurrency issues on TransactionScope timeout #3483
Fix concurrency issues on TransactionScope timeout #3483
Conversation
9503506
to
591ef23
Compare
while (context == null && timeOutGuard.ElapsedMilliseconds < _systemTransactionCompletionLockTimeout) | ||
{ | ||
// Na�ve yield. | ||
Thread.Sleep(10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do this somehow without spin lock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could, if we were putting thread locking mechanisms directly in the session, probably whatever the transaction mechanism, instead of keeping them in the transaction factory and applied only on transaction scope finalization.
The Wait
done by BeginProcess
actually belongs to the transaction factory and does nothing by default: it locks only during transaction scope finalization. This was done that way to minimize the impact of locks required to handle the transaction scope end processing occurring on concurrent threads.
As a result, when the session initiates some processing inside an ongoing transaction scope, no locks are applied. So, when a transaction timeout occurs concurrently to the session processing, we have no locking mechanism enabled against which we could wait for the end of the session processing.
src/NHibernate/Transaction/AdoNetWithSystemTransactionFactory.cs
Outdated
Show resolved
Hide resolved
de3fd8a
to
a9a5cc3
Compare
src/NHibernate/Transaction/AdoNetWithSystemTransactionFactory.cs
Outdated
Show resolved
Hide resolved
src/NHibernate/Transaction/AdoNetWithSystemTransactionFactory.cs
Outdated
Show resolved
Hide resolved
src/NHibernate/Transaction/AdoNetWithSystemTransactionFactory.cs
Outdated
Show resolved
Hide resolved
src/NHibernate/Transaction/AdoNetWithSystemTransactionFactory.cs
Outdated
Show resolved
Hide resolved
233e291
to
d3d1f14
Compare
Rebased and forced pushed to have all the Teamcity build and maybe fix the WIP status which seems to have some failures for whatever reason. |
eb0224c
to
cff5d98
Compare
src/NHibernate/Transaction/AdoNetWithSystemTransactionFactory.cs
Outdated
Show resolved
Hide resolved
The PostGreSQL build has failed with error:
I do not reproduce it locally. There are no trace of an unhandled exception, which would have prevented the session disposal. I am relaunching that build to check if that is systematic or flaky. |
Instead of relying on concurrent session usages to do it through BeginProcess.
This reverts commit 78639a6.
2161490
to
06013ad
Compare
// A concurrency issue exists with the legacy setting allowing to use the session from transaction completion, which | ||
// may cause session leaks. Ignore them. | ||
FailOnNotClosedSession = !UseConnectionOnSystemTransactionPrepare; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PostgreSQL CI has again failed with the session leak. I am adding a condition to ignore that leak.
As this sometimes happens, the Oracle build had a timeout, taking more than one hour to complete. On relaunch, it had worked. |
fix #3355
Possible breaking changes:
transaction.ignore_session_synchronization_failures
.transaction.system_completion_lock_timeout
has been lowered from 5000 (5 seconds) to 1000 (1 second).