Skip to content
Merged
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
54 changes: 31 additions & 23 deletions Orm/Xtensive.Orm/Orm/Domain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -436,41 +436,49 @@ internal Domain(DomainConfiguration configuration, object upgradeContextCookie,

public ValueTask DisposeAsync() => InnerDispose(true);

public ValueTask InnerDispose(bool isAsync)
public async ValueTask InnerDispose(bool isAsync)
{
lock (disposeGuard) {
if (isDisposed) {
return default;
return;
}

isDisposed = true;
}

if (isDebugEventLoggingEnabled) {
OrmLog.Debug(Strings.LogDomainIsDisposing);
}
if (isDebugEventLoggingEnabled) {
OrmLog.Debug(Strings.LogDomainIsDisposing);
}

NotifyDisposing();
Services.Dispose();
NotifyDisposing();
Services.Dispose();

if (SingleConnection==null) {
return default;
}
if (SingleConnection == null) {
return;
}

// TODO: implement async dispose of the SingleConnection
lock (singleConnectionGuard) {
if (singleConnectionOwner==null) {
var driver = Handlers.StorageDriver;
driver.CloseConnection(null, SingleConnection);
driver.DisposeConnection(null, SingleConnection);
}
else {
OrmLog.Warning(
Strings.LogUnableToCloseSingleAvailableConnectionItIsStillUsedBySessionX,
singleConnectionOwner);
}
SqlConnection singleConnectionLocal;
lock (singleConnectionGuard) {
if (singleConnectionOwner != null) {
OrmLog.Warning(
Strings.LogUnableToCloseSingleAvailableConnectionItIsStillUsedBySessionX,
singleConnectionOwner);
return;
}
else {
singleConnectionLocal = SingleConnection;
SingleConnection = null;
}
}

return default;
var driver = Handlers.StorageDriver;
if (isAsync) {
await driver.CloseConnectionAsync(null, singleConnectionLocal).ConfigureAwait(false);
await driver.DisposeConnectionAsync(null, singleConnectionLocal).ConfigureAwait(false);
}
else {
driver.CloseConnection(null, singleConnectionLocal);
driver.DisposeConnection(null, singleConnectionLocal);
}
}
}
Expand Down