Dropping all the events published while the connection is down


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


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




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

var settings = ConnectionSettings









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).


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