Skip to content

Commit

Permalink
Fix bug that DealerSocket has been broken after IBD.
Browse files Browse the repository at this point in the history
  • Loading branch information
longfin committed Jul 1, 2019
1 parent 718cb33 commit f3b8df9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ To be released.

- Fixed a bug that `Swarm` reported `TaskCanceledException` as an unknown
exception while stopping. [[#275]]
- Fixed a bug that `Swarm` didn't stop properly during `Swarm.Preload()`.
[[#275]]
- Fixed a bug that `Swarm` didn't stop properly during
`Swarm.PreloadAsync()`. [[#275]]
- Fixed a bug where the oldest `TxNonce` of an address is not invalidated
when forking using `FileStore.ForkTxNonce()` method. [[#281]]
- Fixed a bug where `LiteDBStore.GetTxNonce()` method throws a
Expand All @@ -91,6 +91,8 @@ To be released.
- Fixed a bug that `KeyNotFoundException` had been thrown instead of
`ArgumentOutOfRangeException` when `Blockchain<T>[int]` called while the
index of a block that does not exist locally. [[#208], [#317]]
- Fixed a bug that `Swarm` had not dial to other peer after
`Swarm.PreloadAsync()`. [[#311]]


[LiteDB]: https://www.litedb.org/
Expand All @@ -116,6 +118,7 @@ To be released.
[#308]: https://github.com/planetarium/libplanet/pull/308
[#309]: https://github.com/planetarium/libplanet/issues/309
[#310]: https://github.com/planetarium/libplanet/pull/310
[#311]: https://github.com/planetarium/libplanet/pull/311
[#317]: https://github.com/planetarium/libplanet/pull/317


Expand Down
10 changes: 8 additions & 2 deletions Libplanet/Net/Swarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public Swarm(

_dealers = new ConcurrentDictionary<Address, DealerSocket>();
_router = new RouterSocket();
_router.Options.RouterHandover = true;
_replyQueue = new NetMQQueue<Message>();
_broadcastQueue = new NetMQQueue<Message>();
_queuePoller = new NetMQPoller { _replyQueue, _broadcastQueue };
Expand Down Expand Up @@ -1717,11 +1718,16 @@ private async Task<Pong> DialPeerAsync(
await CreatePermission(peer);
}

if (!_dealers.TryGetValue(peer.Address, out DealerSocket dealer))
// We create a new DealerSocket for each DialPeerAsync()
// because NetMQ doesn't handle properly previosuly connected sockets.
if (_dealers.TryGetValue(peer.Address, out DealerSocket dealer))
{
dealer = new DealerSocket();
dealer.Dispose();
}

dealer = new DealerSocket();
dealer.Options.Identity = Address.ToByteArray();

try
{
_logger.Debug($"Trying to DialAsync({peer.EndPoint})...");
Expand Down

0 comments on commit f3b8df9

Please sign in to comment.