Kaynağa Gözat

Fix memory leak when using transction to publish message. (#816)

master
Savorboard 3 yıl önce
ebeveyn
işleme
3ca108328b
8 değiştirilmiş dosya ile 11 ekleme ve 17 silme
  1. +1
    -3
      src/DotNetCore.CAP.MongoDB/CAP.MongoDBCapOptionsExtension.cs
  2. +1
    -1
      src/DotNetCore.CAP.MongoDB/ICapTransaction.MongoDB.cs
  3. +0
    -1
      src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs
  4. +2
    -2
      src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs
  5. +0
    -1
      src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs
  6. +2
    -2
      src/DotNetCore.CAP.PostgreSql/ICapTransaction.PostgreSql.cs
  7. +0
    -1
      src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs
  8. +5
    -6
      src/DotNetCore.CAP.SqlServer/ICapTransaction.SqlServer.cs

+ 1
- 3
src/DotNetCore.CAP.MongoDB/CAP.MongoDBCapOptionsExtension.cs Dosyayı Görüntüle

@@ -25,9 +25,7 @@ namespace DotNetCore.CAP.MongoDB
services.AddSingleton<CapStorageMarkerService>();

services.AddSingleton<IDataStorage, MongoDBDataStorage>();
services.AddSingleton<IStorageInitializer, MongoDBStorageInitializer>();

services.AddTransient<ICapTransaction, MongoDBCapTransaction>();
services.AddSingleton<IStorageInitializer, MongoDBStorageInitializer>();

services.Configure(_configure);



+ 1
- 1
src/DotNetCore.CAP.MongoDB/ICapTransaction.MongoDB.cs Dosyayı Görüntüle

@@ -81,7 +81,7 @@ namespace DotNetCore.CAP
ICapPublisher publisher, bool autoCommit = false)
{
var clientSessionHandle = client.StartSession();
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>();
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<MongoDBCapTransaction>(publisher.ServiceProvider);
var capTrans = publisher.Transaction.Value.Begin(clientSessionHandle, autoCommit);
return new CapMongoDbClientSessionHandle(capTrans);
}


+ 0
- 1
src/DotNetCore.CAP.MySql/CAP.MySqlCapOptionsExtension.cs Dosyayı Görüntüle

@@ -26,7 +26,6 @@ namespace DotNetCore.CAP
services.AddSingleton<IDataStorage, MySqlDataStorage>();
services.TryAddSingleton<IStorageInitializer, MySqlStorageInitializer>();
services.AddTransient<ICapTransaction, MySqlCapTransaction>();

//Add MySqlOptions
services.Configure(_configure);


+ 2
- 2
src/DotNetCore.CAP.MySql/ICapTransaction.MySql.cs Dosyayı Görüntüle

@@ -121,7 +121,7 @@ namespace DotNetCore.CAP
ICapPublisher publisher, bool autoCommit = false)
{
var trans = database.BeginTransaction();
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>();
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<MySqlCapTransaction>(publisher.ServiceProvider);
var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit);
return new CapEFDbTransaction(capTrans);
}
@@ -142,7 +142,7 @@ namespace DotNetCore.CAP
}

var dbTransaction = dbConnection.BeginTransaction();
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>();
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<MySqlCapTransaction>(publisher.ServiceProvider);
return publisher.Transaction.Value.Begin(dbTransaction, autoCommit);
}
}

+ 0
- 1
src/DotNetCore.CAP.PostgreSql/CAP.PostgreSqlCapOptionsExtension.cs Dosyayı Görüntüle

@@ -27,7 +27,6 @@ namespace DotNetCore.CAP

services.AddSingleton<IDataStorage, PostgreSqlDataStorage>();
services.AddSingleton<IStorageInitializer, PostgreSqlStorageInitializer>();
services.AddTransient<ICapTransaction, PostgreSqlCapTransaction>();
}
}
}

+ 2
- 2
src/DotNetCore.CAP.PostgreSql/ICapTransaction.PostgreSql.cs Dosyayı Görüntüle

@@ -124,7 +124,7 @@ namespace DotNetCore.CAP
if (dbConnection.State == ConnectionState.Closed) dbConnection.Open();

var dbTransaction = dbConnection.BeginTransaction();
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>();
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<PostgreSqlCapTransaction>(publisher.ServiceProvider);
return publisher.Transaction.Value.Begin(dbTransaction, autoCommit);
}

@@ -139,7 +139,7 @@ namespace DotNetCore.CAP
ICapPublisher publisher, bool autoCommit = false)
{
var trans = database.BeginTransaction();
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>();
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<PostgreSqlCapTransaction>(publisher.ServiceProvider);
var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit);
return new CapEFDbTransaction(capTrans);
}


+ 0
- 1
src/DotNetCore.CAP.SqlServer/CAP.SqlServerCapOptionsExtension.cs Dosyayı Görüntüle

@@ -29,7 +29,6 @@ namespace DotNetCore.CAP
services.AddSingleton<DiagnosticProcessorObserver>();
services.AddSingleton<IDataStorage, SqlServerDataStorage>();
services.AddSingleton<IStorageInitializer, SqlServerStorageInitializer>();
services.AddTransient<ICapTransaction, SqlServerCapTransaction>();
services.TryAddEnumerable(ServiceDescriptor.Singleton<IProcessingServer, DiagnosticRegister>());

services.Configure(_configure);


+ 5
- 6
src/DotNetCore.CAP.SqlServer/ICapTransaction.SqlServer.cs Dosyayı Görüntüle

@@ -46,14 +46,14 @@ namespace DotNetCore.CAP
if (dbTransaction == null) throw new ArgumentNullException(nameof(DbTransaction));
}

var transactionKey = ((SqlConnection) dbTransaction.Connection).ClientConnectionId;
var transactionKey = ((SqlConnection)dbTransaction.Connection).ClientConnectionId;
if (_diagnosticProcessor.BufferList.TryGetValue(transactionKey, out var list))
{
list.Add(msg);
}
else
{
var msgList = new List<MediumMessage>(1) {msg};
var msgList = new List<MediumMessage>(1) { msg };
_diagnosticProcessor.BufferList.TryAdd(transactionKey, msgList);
}
}
@@ -163,11 +163,10 @@ namespace DotNetCore.CAP
ICapPublisher publisher, bool autoCommit = false)
{
if (dbConnection.State == ConnectionState.Closed) dbConnection.Open();

var dbTransaction = dbConnection.BeginTransaction();
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>();
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<SqlServerCapTransaction>(publisher.ServiceProvider);
var capTransaction = publisher.Transaction.Value.Begin(dbTransaction, autoCommit);
return (IDbTransaction) capTransaction.DbTransaction;
return (IDbTransaction)capTransaction.DbTransaction;
}

/// <summary>
@@ -181,7 +180,7 @@ namespace DotNetCore.CAP
ICapPublisher publisher, bool autoCommit = false)
{
var trans = database.BeginTransaction();
publisher.Transaction.Value = publisher.ServiceProvider.GetService<ICapTransaction>();
publisher.Transaction.Value = ActivatorUtilities.CreateInstance<SqlServerCapTransaction>(publisher.ServiceProvider);
var capTrans = publisher.Transaction.Value.Begin(trans, autoCommit);
return new CapEFDbTransaction(capTrans);
}


Yükleniyor…
İptal
Kaydet