Using the fabric-network NodeJS sdk v2.2, I'm implementing a block listener that has to catch all blocks and parse them.
It should be resilient and automatically reconnect when the peer goes down or is unreachable for a moment. In previous versions of the SDK, we could just use the 'onError' callback and reconnect. Now, that part is abstracted away, you only have something like:
network.addBlockListener(async (blockEvent: BlockEvent) => {
console.log(blockEvent.blockNumber);
});
When I kill the peer, the Gateway and Network are smart enough to reconnect automatically. The blocklistener however is lost. For completeness, here's the error logs when deleting the peer pod.
[ServiceEndpoint]: Error: Failed to connect before the deadline on Eventer- name: peer-0.peer.org1, url:grpcs://peer-0.peer.org1:7051, connected:false, connectAttempted:true
[ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer-0.peer.org1 url:grpcs://peer-0.peer.org1:7051 timeout:3000
[Eventer]: checkConnection[peer-0.peer.org1:3] Event Service grpcs://peer-0.peer.org1:7051 Connection check failed :: Error: Failed to connect before the deadline on Eventer- name: peer-0.peer.org1, url:grpcs://peer-0.peer.org1:7051, connected:false, connectAttempted:true
[EventService]: send[peer-0.peer.org1] - #4 - no targets started - Error: Event service peer-0.peer.org1 is not connected
[BlockEventSource]: Failed to start event service message=Event service peer-0.peer.org1 is not connected, stack=Error: Event service peer-0.peer.org1 is not connected
[ServiceEndpoint]: Error: Failed to connect before the deadline on Eventer- name: peer-0.peer.org1, url:grpcs://peer-0.peer.org1:7051, connected:false, connectAttempted:true
[ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer-0.peer.org1 url:grpcs://peer-0.peer.org1:7051 timeout:3000
After it restarted, I can execute transactions again but the block events aren't coming through anymore.
Is there a way to either catch a kind of 'disconnect' event, to easily create a custom block event listener with connection error handling or another way to reconnect blocklisteners automatically?