Skip to content

Commit

Permalink
Merge pull request #422 from longfin/bugfix/exc-in-turn
Browse files Browse the repository at this point in the history
Continue RefreshAllocate and RefreshPermission even if exc occurred.
  • Loading branch information
earlbread committed Aug 13, 2019
2 parents c00523d + b7cd3ba commit c95530a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Expand Up @@ -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 restarted automatically when an
exception occurred. [[#422]]
- Fixed a bug that TURN relay connection had disconnected when preloading
took a long time. [[#424]]

Expand Down Expand Up @@ -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
Expand Down
45 changes: 40 additions & 5 deletions Libplanet/Net/Swarm.cs
Expand Up @@ -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;
}
}
}

Expand All @@ -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;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Menees.Analyzers.Settings.xml
Expand Up @@ -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 c95530a

Please sign in to comment.