浏览代码

Move the release of the object inside the Return method (#969)

master
油条 3 年前
committed by GitHub
父节点
当前提交
4b7fa15984
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 6 个文件被更改,包括 14 次插入20 次删除
  1. +2
    -0
      src/DotNetCore.CAP.Kafka/IConnectionPool.Default.cs
  2. +1
    -5
      src/DotNetCore.CAP.Kafka/ITransport.Kafka.cs
  3. +4
    -2
      src/DotNetCore.CAP.NATS/IConnectionPool.Default.cs
  4. +3
    -7
      src/DotNetCore.CAP.NATS/ITransport.NATS.cs
  5. +3
    -1
      src/DotNetCore.CAP.RabbitMQ/IConnectionChannelPool.Default.cs
  6. +1
    -5
      src/DotNetCore.CAP.RabbitMQ/ITransport.RabbitMQ.cs

+ 2
- 0
src/DotNetCore.CAP.Kafka/IConnectionPool.Default.cs 查看文件

@@ -60,6 +60,8 @@ namespace DotNetCore.CAP.Kafka
return true;
}

producer.Dispose();

Interlocked.Decrement(ref _pCount);

return false;


+ 1
- 5
src/DotNetCore.CAP.Kafka/ITransport.Kafka.cs 查看文件

@@ -64,11 +64,7 @@ namespace DotNetCore.CAP.Kafka
}
finally
{
var returned = _connectionPool.Return(producer);
if (!returned)
{
producer.Dispose();
}
_connectionPool.Return(producer);
}
}
}

+ 4
- 2
src/DotNetCore.CAP.NATS/IConnectionPool.Default.cs 查看文件

@@ -17,7 +17,7 @@ namespace DotNetCore.CAP.NATS
private readonly ConnectionFactory _connectionFactory;
private int _pCount;
private int _maxSize;
public ConnectionPool(ILogger<ConnectionPool> logger, IOptions<NATSOptions> options)
{
_options = options.Value;
@@ -51,7 +51,7 @@ namespace DotNetCore.CAP.NATS
{
connection = _connectionFactory.CreateConnection(_options.Servers);
}
return connection;
}

@@ -64,6 +64,8 @@ namespace DotNetCore.CAP.NATS
return true;
}

connection.Dispose();

Interlocked.Decrement(ref _pCount);

return false;


+ 3
- 7
src/DotNetCore.CAP.NATS/ITransport.NATS.cs 查看文件

@@ -35,8 +35,8 @@ namespace DotNetCore.CAP.NATS
{
msg.Header[header.Key] = header.Value;
}
var reply= connection.Request(msg);
var reply = connection.Request(msg);

if (reply.Data != null && reply.Data[0] == 1)
{
@@ -54,11 +54,7 @@ namespace DotNetCore.CAP.NATS
}
finally
{
var returned = _connectionPool.Return(connection);
if (!returned)
{
connection.Dispose();
}
_connectionPool.Return(connection);
}
}
}

+ 3
- 1
src/DotNetCore.CAP.RabbitMQ/IConnectionChannelPool.Default.cs 查看文件

@@ -105,7 +105,7 @@ namespace DotNetCore.CAP.RabbitMQ
if (options.HostName.Contains(","))
{
options.ConnectionFactoryOptions?.Invoke(factory);
return () => factory.CreateConnection(
options.HostName.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries));
}
@@ -149,6 +149,8 @@ namespace DotNetCore.CAP.RabbitMQ
return true;
}

connection.Dispose();

Interlocked.Decrement(ref _count);

Debug.Assert(_maxSize == 0 || _pool.Count <= _maxSize);


+ 1
- 5
src/DotNetCore.CAP.RabbitMQ/ITransport.RabbitMQ.cs 查看文件

@@ -67,11 +67,7 @@ namespace DotNetCore.CAP.RabbitMQ
{
if (channel != null)
{
var returned = _connectionChannelPool.Return(channel);
if (!returned)
{
channel.Dispose();
}
_connectionChannelPool.Return(channel);
}
}
}


正在加载...
取消
保存