Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit 67f9e30

Browse files
committed
remove polly dependency #458 ?
1 parent 863ddc9 commit 67f9e30

File tree

4 files changed

+21
-24
lines changed

4 files changed

+21
-24
lines changed

Titanium.Web.Proxy/Network/RetryPolicy.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using Polly;
2-
using System;
1+
using System;
32
using System.Threading.Tasks;
43
using Titanium.Web.Proxy.Network.Tcp;
54

@@ -11,14 +10,11 @@ internal class RetryPolicy<T> where T : Exception
1110
private readonly TcpConnectionFactory tcpConnectionFactory;
1211

1312
private TcpServerConnection currentConnection;
14-
private Policy policy;
1513

1614
internal RetryPolicy(int retries, TcpConnectionFactory tcpConnectionFactory)
1715
{
1816
this.retries = retries;
1917
this.tcpConnectionFactory = tcpConnectionFactory;
20-
21-
policy = getRetryPolicy();
2218
}
2319

2420
/// <summary>
@@ -32,38 +28,42 @@ internal async Task<RetryResult> ExecuteAsync(Func<TcpServerConnection, Task<boo
3228
Func<Task<TcpServerConnection>> generator, TcpServerConnection initialConnection)
3329
{
3430
currentConnection = initialConnection;
35-
Exception exception = null;
3631
bool @continue = true;
32+
Exception exception = null;
3733

38-
try
34+
var attempts = retries;
35+
while (attempts >= 0)
3936
{
40-
//retry on error with polly policy
41-
//do not use polly context to store connection; it does not save states b/w attempts
42-
await policy.ExecuteAsync(async () =>
37+
38+
try
4339
{
4440
//setup connection
4541
currentConnection = currentConnection as TcpServerConnection ??
4642
await generator();
4743
//try
4844
@continue = await action(currentConnection);
4945

50-
});
46+
}
47+
catch (T ex)
48+
{
49+
exception = ex;
50+
await onRetry(ex);
51+
}
52+
53+
if(exception == null)
54+
{
55+
break;
56+
}
57+
58+
exception = null;
59+
attempts--;
5160
}
52-
catch (Exception e) { exception = e; }
5361

5462
return new RetryResult(currentConnection, exception, @continue);
5563
}
5664

57-
//get the policy
58-
private Policy getRetryPolicy()
59-
{
60-
return Policy.Handle<T>()
61-
.RetryAsync(retries,
62-
onRetryAsync: onRetry);
63-
}
64-
6565
//before retry clear connection
66-
private async Task onRetry(Exception ex, int attempt)
66+
private async Task onRetry(Exception ex)
6767
{
6868
if (currentConnection != null)
6969
{

Titanium.Web.Proxy/Titanium.Web.Proxy.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Polly" Version="6.0.1" />
1615
<PackageReference Include="Portable.BouncyCastle" Version="1.8.2" />
1716
<PackageReference Include="StreamExtended" Version="1.0.179" />
1817
</ItemGroup>

Titanium.Web.Proxy/Titanium.Web.Proxy.nuspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<dependencies>
1717
<dependency id="StreamExtended" version="1.0.179" />
1818
<dependency id="Portable.BouncyCastle" version="1.8.2" />
19-
<dependency id="Polly" version="6.0.1"/>
2019
</dependencies>
2120
</metadata>
2221
<files>

Titanium.Web.Proxy/packages.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
<packages>
44
<package id="Portable.BouncyCastle" version="1.8.2" targetFramework="net45" />
55
<package id="StreamExtended" version="1.0.179" targetFramework="net45" />
6-
<package id="Polly" version="6.0.1" targetFramework="net45" />
76
</packages>

0 commit comments

Comments
 (0)