Skip to content

Commit 5ea4fc6

Browse files
fixup! Fix some NRE in work isolation and connection handling
1 parent 1b90291 commit 5ea4fc6

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

src/NHibernate/Async/Transaction/AdoNetTransactionFactory.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,15 @@ public virtual Task ExecuteWorkInIsolationAsync(ISessionImplementor session, IIs
4040
async Task InternalExecuteWorkInIsolationAsync()
4141
{
4242

43-
DbConnection connection = null;
4443
DbTransaction trans = null;
4544
// bool wasAutoCommit = false;
45+
// We make an exception for SQLite and use the session's connection,
46+
// since SQLite only allows one connection to the database.
47+
var connection = session.Factory.Dialect is SQLiteDialect
48+
? session.Connection
49+
: await (session.Factory.ConnectionProvider.GetConnectionAsync(cancellationToken)).ConfigureAwait(false);
4650
try
4751
{
48-
// We make an exception for SQLite and use the session's connection,
49-
// since SQLite only allows one connection to the database.
50-
if (session.Factory.Dialect is SQLiteDialect)
51-
connection = session.Connection;
52-
else
53-
connection = await (session.Factory.ConnectionProvider.GetConnectionAsync(cancellationToken)).ConfigureAwait(false);
5452

5553
if (transacted)
5654
{
@@ -126,7 +124,7 @@ async Task InternalExecuteWorkInIsolationAsync()
126124
isolaterLog.Warn(ignore, "Unable to dispose transaction");
127125
}
128126

129-
if (connection != null && session.Factory.Dialect is SQLiteDialect == false)
127+
if (session.Factory.Dialect is SQLiteDialect == false)
130128
session.Factory.ConnectionProvider.CloseConnection(connection);
131129
}
132130
}

src/NHibernate/Transaction/AdoNetTransactionFactory.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,15 @@ public virtual void ExecuteWorkInIsolation(ISessionImplementor session, IIsolate
5050
if (work == null)
5151
throw new ArgumentNullException(nameof(work));
5252

53-
DbConnection connection = null;
5453
DbTransaction trans = null;
5554
// bool wasAutoCommit = false;
55+
// We make an exception for SQLite and use the session's connection,
56+
// since SQLite only allows one connection to the database.
57+
var connection = session.Factory.Dialect is SQLiteDialect
58+
? session.Connection
59+
: session.Factory.ConnectionProvider.GetConnection();
5660
try
5761
{
58-
// We make an exception for SQLite and use the session's connection,
59-
// since SQLite only allows one connection to the database.
60-
if (session.Factory.Dialect is SQLiteDialect)
61-
connection = session.Connection;
62-
else
63-
connection = session.Factory.ConnectionProvider.GetConnection();
6462

6563
if (transacted)
6664
{
@@ -136,7 +134,7 @@ public virtual void ExecuteWorkInIsolation(ISessionImplementor session, IIsolate
136134
isolaterLog.Warn(ignore, "Unable to dispose transaction");
137135
}
138136

139-
if (connection != null && session.Factory.Dialect is SQLiteDialect == false)
137+
if (session.Factory.Dialect is SQLiteDialect == false)
140138
session.Factory.ConnectionProvider.CloseConnection(connection);
141139
}
142140
}

0 commit comments

Comments
 (0)