Receiving intermittent NotAuthenticatedException

Hi all,

I have an integration tests that fails intermittently with the following exception being thrown on a call to AppendToStream() :-

EventStore.ClientAPI.Exceptions.NotAuthenticatedException: Not Authenticated

at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)

at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)

at EventStore.ClientAPI.EventStoreNodeConnection.AppendToStream(String stream, Int32 expectedVersion, IEnumerable`1 events, UserCredentials userCredentials)

The credentials are being set via ConnectionSettings.SetDefaultUserCredentials().

As part of the integration test the EventStore process is terminated and restarted after the connection is established but before the call to AppendToStream.

Any ideas why the NotAuthenticatedException is sometimes thrown?


I am also seeing this issue when running ES in its in-memory mode (–mem-db). I will get this error if the EventStore process has not finished starting. My current hack for this is to Sleep for 5 seconds. :frowning:

It seems to me that either

  • there is a bug that ES does not internally wait from some sort of Initialized state before processing AppendToStream (or in my case SubscribeToAllAsync) method
  • there is a feature missing, not documented, or that I am unaware of, that allows me to gate my actions on the system being initialized. i.e. either an Event, WaitHandle or callback that can let me know that I can now access the system with a given user (in my test case just admin:changeit)
    Has any one had any experience with this


(ES Newbie)

I will take a look at the new embedded client. There is an event when hosting event store that represents the system being ready.

I will also check out the apprend to stream too early. Likely the messages just needs to be gated in the vnode controlller fsm



So I did some research on this.

The code in question:

if (completed.Result != ReadStreamResult.Success)





Is whats causing it. Early in the life cycle the read gets rejected as the system is not yet ready. I added a NotReady status to the authentication which will give you a message to this regard over TCP and will give you a 503 + retry-after header for http (seems reasonable) PR will be up shortly.

For the state notifications for hosting event store yourself (eg embedded client) there is now an event on clustervnode that will let you know about state transitions its here: this will allow you in your code to

myNode.NodeStatusChanged += handler to get any status updates from your self hosted vnode.

PR is here for those who may be interested: