msemys / esjc

EventStore Java Client
MIT License
108 stars 27 forks source link

Lost dropData in CatchUpSubscription in case of quick reconnect (concurrency issue). #53

Closed jezovuk closed 4 years ago

jezovuk commented 5 years ago

Consider the following scenario:

Note that various other semi-problematic scenarios are available in case of reconnect before drop event is processed, but most of those seem to be covered by various checks. The most obvious possible problem is as follows:

Suggested solution is to wait in runSubscription until previous drop is processed (in case it is enqueued).

Illustrative code:

Replace

isDropped.set(false);
dropData.set(null);

with

while (dropData.get() != null && !isDropped.get()) {}
isDropped.set(false);
dropData.set(null);

(some kind of wait/signal would probably make sense instead of busy-waiting in while loop, but idea is the same - if dropData is set and isDropped is still false, wait).