Closed longfin closed 1 year ago
When peers are no longer available on NineChronicles.Headless
due to various reasons (i.e. Internet disconnection), System.InvalidOperationException: The operation is not allowed on non-connected sockets
error keeps occurring and peers cannot be reconnected even when the issue is resolved.
PeerChainState
on http://localhost:23061/ui/playground and make sure peers are connected.
PeerChainState
on http://localhost:23061/ui/playground and check that peers are not connected and find System.InvalidOperationException: The operation is not allowed on non-connected sockets.
on the debug log.
Once the Internet is reconnected, re-querying PeerChainState
on http://localhost:23061/ui/playground should restore reconnected peers and System.InvalidOperationException: The operation is not allowed on non-connected sockets.
should no longer appear the debug log.
However, the PeerChainState
query on http://localhost:23061/ui/playground shows that peers are still unavailable even after reconnecting to the Internet and System.InvalidOperationException: The operation is not allowed on non-connected sockets.
continues to appear on the debug log.
Wrapping https://github.com/planetarium/libplanet/blob/main/Libplanet.Stun/Stun/TurnClient.cs#L160-L177 with a try-catch block to ignore the InvalidOperationException
does enable PeerChainState
to be restored after reconnecting to the Internet.
Example
public async Task CreatePermissionAsync( IPEndPoint peerAddress, CancellationToken cancellationToken = default(CancellationToken)) { try { NetworkStream stream = _control.GetStream(); var request = new CreatePermissionRequest(peerAddress); await SendMessageAsync(stream, request, cancellationToken); StunMessage response = await ReceiveMessageAsync( request.TransactionId, cancellationToken); if (response is CreatePermissionErrorResponse) { throw new TurnClientException( "CreatePermission failed.", response); } } catch (InvalidOperationException ex) { Log.Debug("Error Message: {0}", ex.Message); } }
However, the System.InvalidOperationException: The operation is not allowed on non-connected sockets.
continues to appear on the debug log despite the restored peer connection.
NOTE! ) Even after the PeerChainState
is restored, the headless client is unable to receive new blocks from its peers.
I think that the non-connected sockets
should be cleaned up once the peer connection is restored but I'm not entirely sure how and where in the Libplanet
code to implement this.
This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.