Skip to content

Commit 71425ef

Browse files
committed
retry mechanism
1 parent 3db755b commit 71425ef

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/SocketIOClient/Transport/TransportRouter.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,40 @@ private async Task OnOpened(OpenedMessage msg)
180180
Eio = EIO,
181181
Query = _options.Query
182182
};
183-
await SendAsync(connectMsg.Write(), CancellationToken.None).ConfigureAwait(false);
183+
184+
for (int i = 1; i <= 3; i++)
185+
{
186+
try
187+
{
188+
await SendAsync(connectMsg.Write(), CancellationToken.None).ConfigureAwait(false);
189+
break;
190+
}
191+
catch (Exception e)
192+
{
193+
if (i == 3)
194+
Trace.TraceError(e.ToString());
195+
else
196+
await Task.Delay(TimeSpan.FromMilliseconds(Math.Pow(2, i) * 100));
197+
}
198+
}
199+
/*
200+
try
201+
{
202+
await Policy
203+
.Handle<Exception>()
204+
.WaitAndRetryAsync(3, attempt => TimeSpan.FromMilliseconds(Math.Pow(2, attempt) * 100))
205+
.ExecuteAsync(async () =>
206+
{
207+
await SendAsync(connectMsg.Write(), CancellationToken.None).ConfigureAwait(false);
208+
}).ConfigureAwait(false);
209+
210+
}
211+
catch (Exception e)
212+
{
213+
Trace.TraceError(e.ToString());
214+
OnTransportClosed();
215+
}
216+
*/
184217
}
185218

186219
private async void OnTextReceived(string text)

0 commit comments

Comments
 (0)