Skip to content

Commit

Permalink
Fix SapConnectionPool when connection.Connect() throws
Browse files Browse the repository at this point in the history
  • Loading branch information
campersau committed May 13, 2022
1 parent b5c6605 commit 0d4351b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/SapNwRfc/Pooling/SapConnectionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,16 @@ public ISapConnection GetConnection(CancellationToken cancellationToken = defaul

if (connection != null)
{
connection.Connect();
try
{
connection.Connect();
}
catch
{
lock (_syncRoot) _openConnectionCount--;
throw;
}

return connection;
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/SapNwRfc/Pooling/SapPooledConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ public void InvokeFunction(string name, CancellationToken cancellationToken = de
/// <inheritdoc cref="ISapPooledConnection"/>
public void InvokeFunction(string name, object input, CancellationToken cancellationToken = default)
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);

try
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);
using (ISapFunction function = _connection.CreateFunction(name))
function.Invoke(input);
}
Expand All @@ -94,9 +95,10 @@ public void InvokeFunction(string name, object input, CancellationToken cancella
/// <inheritdoc cref="ISapPooledConnection"/>
public TOutput InvokeFunction<TOutput>(string name, CancellationToken cancellationToken = default)
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);

try
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);
using (ISapFunction function = _connection.CreateFunction(name))
return function.Invoke<TOutput>();
}
Expand All @@ -115,9 +117,10 @@ public TOutput InvokeFunction<TOutput>(string name, CancellationToken cancellati
/// <inheritdoc cref="ISapPooledConnection"/>
public TOutput InvokeFunction<TOutput>(string name, object input, CancellationToken cancellationToken = default)
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);

try
{
_connection = _connection ?? _pool.GetConnection(cancellationToken);
using (ISapFunction function = _connection.CreateFunction(name))
return function.Invoke<TOutput>(input);
}
Expand Down

0 comments on commit 0d4351b

Please sign in to comment.