SubscribeToAllAsync is not aware of start position being invalid

Before subscribing to EventStoreDb, I retrieve the last known position and then I use the EventStoreClient to subscribe to all from that position (gRPC client).

Is there any way to validate that a position really exists in order to subscribe or fallback to default position 0?

Probably it’s not very common to remember a “last position” that might be invalid after some time (unless events are removed from ESDB or the cluster subscribing to is different), but if there is already a way,
but I have noticed that eventStoreClient.SubscribeToAllAsync(position, eventAppeared) method does not throw any exception if the position is invalid, nor the StreamSubscription result contains any flag indicating that the start position was invalid.
The subscription seems to happen, but it won’t receive any events.

Would verifying the position in advance be a valid suggestion?

If the position is 0 it works fine, catches up from the beginning. If the position is 1, 2, 100 or other (similar?) it crashes. If the position is a random number such as 12345 or 66666 it doesn’t crash, but won’t receive any event.

Seems like a bug, I think you might want to open an issue in the gRPC client repo.

I remember that the TCP client was throwing if the position isn’t valid. But, it might be that it behaves similarly to what you observe, we just never noticed. We also used to get this issue rather frequently (but it was crashing, so we knew), forcing us to discover the correct position, update it manually in the checkpoint store, and start again. Since a few v5 minor versions back, we never had this issue. I remember we opened an issue in the server repo, and it has been resolved.

By the way, deleting events does not change the global position for events that are still there. But indeed, if those events are gone and you resubscribe, you might hit a position of a scavenged event. Honestly, I am not sure what will happen. The upcoming changes in the log structure will solve this issue ultimately, by the way. I don’t know exactly where it will be out, but it will be.