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

Avoid overwrapped SetResult and SetException #864

Merged
merged 2 commits into from
May 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
8 changes: 6 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ To be released.

### Bug fixes

- Fixed a bug where the canonical chain had changed if any actions had thrown an exception
during `Swarm<T>.PreloadAsync()`. [[#862]]
- Fixed a bug where the canonical chain had changed if any actions had thrown
an exception during `Swarm<T>.PreloadAsync()`. [[#862]]
- Fixed a `Swarm<T>.PreloadAsync()` method's bug that it had hung forever and
raised `InvalidOperationException`. [[#847], [#864]]

[#847]: https://github.com/planetarium/libplanet/issues/847
[#862]: https://github.com/planetarium/libplanet/pull/862
[#864]: https://github.com/planetarium/libplanet/pull/864

Version 0.9.0
-------------
Expand Down
8 changes: 5 additions & 3 deletions Libplanet/Net/NetMQTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ public async Task<IEnumerable<Message>> SendMessageWithReplyAsync(
);
var tcs = new TaskCompletionSource<IEnumerable<Message>>();
Interlocked.Increment(ref _requestCount);

// FIXME should we also cancel tcs sender side too?
cancellationToken.Register(() => tcs.TrySetCanceled());
await _requests.AddAsync(
new MessageRequest(reqId, message, peer, now, timeout, expectedResponses, tcs),
Expand Down Expand Up @@ -836,15 +838,15 @@ await dealer.SendMultipartMessageAsync(
Protocol.ReceiveMessage(result[0]);
}

tcs.SetResult(result);
tcs.TrySetResult(result);
}
catch (DifferentAppProtocolVersionException dape)
{
tcs.SetException(dape);
tcs.TrySetException(dape);
}
catch (TimeoutException te)
{
tcs.SetException(te);
tcs.TrySetException(te);
}

// Delaying dealer disposing to avoid ObjectDisposedException on NetMQPoller
Expand Down