Skip to content
Permalink
Browse files

Continue RefreshAllocate and RefreshPermission even if exception occu…

…rred.
  • Loading branch information...
longfin committed Aug 13, 2019
1 parent c00523d commit 732ddfbf78467677d30bf7825b31799da02de60a
Showing with 44 additions and 6 deletions.
  1. +3 −0 CHANGES.md
  2. +40 −5 Libplanet/Net/Swarm.cs
  3. +1 −1 Menees.Analyzers.Settings.xml
@@ -102,6 +102,8 @@ To be released.
disconnected while receiving. [[#416]]
- Fixed a bug that `Swarm<T>.PreloadAsync()` had been processed even if there
is no appropriate peer. [[#418]]
- Fixed a bug that TURN related tasks hadn't restart automatically when an
exception occurred. [[#422]]
- Fixed a bug that TURN relay connection had disconnected when preloading
took a long time. [[#424]]

@@ -135,6 +137,7 @@ To be released.
[#417]: https://github.com/planetarium/libplanet/pull/417
[#418]: https://github.com/planetarium/libplanet/pull/418
[#419]: https://github.com/planetarium/libplanet/pull/419
[#422]: https://github.com/planetarium/libplanet/pull/422
[#423]: https://github.com/planetarium/libplanet/pull/423
[#424]: https://github.com/planetarium/libplanet/pull/424
[#426]: https://github.com/planetarium/libplanet/pull/426
@@ -1100,8 +1100,25 @@ private async Task RefreshAllocate(CancellationToken cancellationToken)
TimeSpan lifetime = TurnAllocationLifetime;
while (!cancellationToken.IsCancellationRequested)
{
await Task.Delay(lifetime - TimeSpan.FromMinutes(1));
lifetime = await _turnClient.RefreshAllocationAsync(lifetime);
try
{
await Task.Delay(lifetime - TimeSpan.FromMinutes(1), cancellationToken);
lifetime = await _turnClient.RefreshAllocationAsync(lifetime);
cancellationToken.ThrowIfCancellationRequested();
}
catch (OperationCanceledException e)
{
_logger.Warning(e, $"{nameof(RefreshAllocate)}() is cancelled.");
throw;
}
catch (Exception e)
{
_logger.Error(
e,
$"An unexpected exception occurred during {nameof(RefreshAllocate)}(): {e}"
);
continue;
}
}
}

@@ -1111,9 +1128,27 @@ private async Task RefreshAllocate(CancellationToken cancellationToken)
TimeSpan lifetime = TurnPermissionLifetime;
while (!cancellationToken.IsCancellationRequested)
{
await Task.Delay(lifetime - TimeSpan.FromMinutes(1));
await Task.WhenAll(
_peers.Keys.Select(CreatePermission));
try
{
await Task.Delay(lifetime - TimeSpan.FromMinutes(1), cancellationToken);
await Task.WhenAll(_peers.Keys.Select(CreatePermission));
cancellationToken.ThrowIfCancellationRequested();
}
catch (OperationCanceledException e)
{
_logger.Warning(e, $"{nameof(RefreshPermissions)}() is cancelled.");
throw;
}
catch (Exception e)
{
_logger.Error(
e,
#pragma warning disable MEN002 // Line is too long
$"An unexpected exception occurred during {nameof(RefreshPermissions)}(): {e}"
#pragma warning restore MEN002 // Line is too long
);
continue;
}
}
}

@@ -2,5 +2,5 @@
<Menees.Analyzers.Settings>
<MaxLineColumns>100</MaxLineColumns>
<MaxMethodLines>200</MaxMethodLines>
<MaxFileLines>2200</MaxFileLines>
<MaxFileLines>2250</MaxFileLines>
</Menees.Analyzers.Settings>

0 comments on commit 732ddfb

Please sign in to comment.
You can’t perform that action at this time.