EventStore / EventStoreDB-Client-Java

Official Asynchronous Java 8+ Client Library for EventStoreDB 20.6+
https://eventstore.com
Apache License 2.0
63 stars 20 forks source link

Failover does not properly work on read operations. #171

Closed dpasek-senacor closed 2 years ago

dpasek-senacor commented 2 years ago

This is a regression caused by the implementation of the reactive stream support for the stream read operations. (Shame on me. :-) )

Situation

EventStoreDBClient performs a read stream operation and the underlying GrpcClient receives:

Expected bevahior:

The existing gRPC connection (aka the ManagedChannel) is dropped a new conection to a node is created. In case of the NotLeaderException the new connection should be to the node specified in the Exception.

Current behavior:

Impact

After a leader change in a cluster the client will try to reconnect to the old node and will not switch to the new master, causing operations to fail.

Root cause

Inside the implementation of AbstractRead the error signals of the gRPC connection are only forward to the reactive subscriber but not to the GrpcClient since the result of AbstractRead is always a successfully completed CompletableFuture containing the subscription. It is necessary to forward the error signals to the reactive subscriber and provide a CompletableFuture for the GrpcClient to receive error signals.