Skip to content

Commit

Permalink
Avoid overwrapped SetResult and SetException
Browse files Browse the repository at this point in the history
  • Loading branch information
longfin committed May 7, 2020
1 parent d372c8e commit 7f3e814
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
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
raisen `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 cacel 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

0 comments on commit 7f3e814

Please sign in to comment.