Dropping all the events published while the connection is down

Hi

Based on what I have observed while testing and this piece of code:

https://github.com/EventStore/EventStore/blob/ed7e01c034dd41d0b556c78941ab8da93ac7a038/src/EventStore.ClientAPI/Internal/EventStoreConnectionLogicHandler.cs#L378

it seems like any event published while the connection was down is not lost, but en-queued. Which seems like a really sensible thing to do if one wanted no data loss.

However my scenario is slightly different, I expect some down times and my events are not essential, hence I’d like to be able just immediately get out of AppendToStreamAsync with an error and suffer some event loss (let the bickering begin…), rather than wait for the connection to be restored or the max connect attempts to be reached and then for my append to stream operation to fail (which I presume it is somehow related to StartOperationMessage operation) This is because, during the times where the connection is down (flaky hardware, network saturation, under powered machines, we have all that), I’m concerned I’ll be getting out of memory issues from growing the _operations queue or really just running out of threads (my publish operations are fire and forget). I think the out of memory can be tackled by setting the queue size in connection settings; could be that this protects against the threads issue too, I have not figured that out yet.

Regardless, the solution I have is keeping the state of the connection in my own object, managing it through the connection’s events Connected, Disconnected and Closed, and just checking that prior to calling AppendToStreamAsync.

I’m just wondering if there’s a better “out of the box” solution for achieving this so I don’t reinvent wheels?

Thank you.

You can set whether or not the connection will retry things

https://github.com/EventStore/EventStore/blob/dev/src/EventStore.ClientAPI/ConnectionSettingsBuilder.cs#L131

Cheers,

Greg

Yes, I have set that, my settings look like this now:

var settings = ConnectionSettings

.Create()

.LimitReconnectionsTo(_settings.MaxReconnectionAttemps)

.LimitAttemptsForOperationTo(1)

.LimitRetriesForOperationTo(1)

.SetOperationTimeoutTo(TimeSpan.FromSeconds(10))

.WithConnectionTimeoutOf(TimeSpan.FromSeconds(9))

.SetReconnectionDelayTo(TimeSpan.FromSeconds(10))

.LimitOperationsQueueTo(10000);

but what happens is that my PublishToStreamAsync(…) will throw an exception only after the connection realized it can’t connect - it exhausted all of its connection attempts. So what I’d like to happen is, if the connection is down, immediately throw an exception in PublishToStreamAsync and end it.

Also tried .LimitRetriesForOperationTo(0) but that did not do much that I could see (perhaps missing something here).

+1

I am having to use the http API for this scenario because I can’t get the tcp client to immediately fail appends if the connection is down