Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed TurnClient's cancellation bug #916

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ To be released.
key is not an `Address` when preloading. [[#912]]
- Fixed a bug where `UnexpectedlyTerminatedException` hadn't been serialized
with `BinaryFormatter`. [[#913]]
- Fixed a bug where `TurnClient` hadn't applied cancellation token to its
connections. [[#916]]


### CLI tools

Expand All @@ -104,6 +107,7 @@ To be released.
[#909]: https://github.com/planetarium/libplanet/pull/909
[#912]: https://github.com/planetarium/libplanet/pull/912
[#913]: https://github.com/planetarium/libplanet/pull/913
[#916]: https://github.com/planetarium/libplanet/pull/916
[sleep mode]: https://en.wikipedia.org/wiki/Sleep_mode


Expand Down
5 changes: 3 additions & 2 deletions Libplanet.Stun/Stun/TurnClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ private async Task SendMessageAsync(
StunMessage message,
CancellationToken cancellationToken)
{
_responses[message.TransactionId] =
new TaskCompletionSource<StunMessage>(cancellationToken);
var tcs = new TaskCompletionSource<StunMessage>();
cancellationToken.Register(() => tcs.TrySetCanceled());
_responses[message.TransactionId] = tcs;
var asBytes = message.Encode(this);
await stream.WriteAsync(
asBytes,
Expand Down