Search code examples
c#.net-coreeventstoredb

Trying to append a stream event to EventStore throws Exception


I am currently getting started with EventStore and I'm following the Getting Started guide. And I just got stuck at the first step and don't know what I'm doing wrong...

The version I'm using now is 20.6.0.

I'm trying to write an event using the .NET Core Client to my local instance (which is running because I can add events using the AdminUI). But I get an exception like One or more errors occurred. (Connection 'ES-41230054-2026-4cdb-b2bb-a35824779863' was closed.)'.

After a while trying to fix it, I went to the .Net Client guide and pasted the exact same piece of code:

        public static void Main()
        {
            var conn = EventStoreConnection.Create(new Uri("tcp://admin:changeit@localhost:1113"));
            conn.ConnectAsync().Wait();

            var data = Encoding.UTF8.GetBytes("{\"a\":\"2\"}");
            var metadata = Encoding.UTF8.GetBytes("{}");
            var evt = new EventData(Guid.NewGuid(), "testEvent", true, data, metadata);

            conn.AppendToStreamAsync("test-stream", ExpectedVersion.Any, evt).Wait();

            var streamEvents = conn.ReadStreamEventsForwardAsync("test-stream", 0, 1, false).Result;
            var returnedEvent = streamEvents.Events[0].Event;

            Console.WriteLine("Read event with data: {0}, metadata: {1}",
                Encoding.UTF8.GetString(returnedEvent.Data),
                Encoding.UTF8.GetString(returnedEvent.Metadata));
        }
    }

But the same exception is thrown when I get to this line:

conn.AppendToStreamAsync("test-stream", ExpectedVersion.Any, evt).Wait();

I tried different approaches when creating the connection but none worked so far.

I am wondering if I'm missing some configuration... If anyone has experienced this issue and would shred some light to this for me I'd be greatly thankful.

Adding more info

After activating the logging, I've seen the following:

  • When trying to append the event, I get this output:

[01,07:28:46.528,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': enqueueing message EventStore.ClientAPI.Internal.StartConnectionMessage.. [04,07:28:46.545,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': StartConnection. [04,07:28:46.546,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': DiscoverEndPoint. [04,07:28:46.549,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': enqueueing message EventStore.ClientAPI.Internal.EstablishTcpConnectionMessage.. [06,07:28:46.561,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': EstablishTcpConnection to [127.0.0.1:1113]. [05,07:28:46.582,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': enqueueing message EventStore.ClientAPI.Internal.StartOperationMessage.. [06,07:28:46.642,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': StartOperation enqueue AppendToStreamOperation, Stream: newstream, ExpectedVersion: -2, 10, 00:00:07.. [06,07:28:46.643,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': EnqueueOperation WAITING for Operation AppendToStreamOperation (a301f19c-bb92-4c53-a193-3a81582a49db): Stream: newstream, ExpectedVersion: -2, retry count: 0, created: 07:28:46.642, last updated: 07:28:46.642.. [08,07:28:48.702,DEBUG] TcpPackageConnection: connection to [127.0.0.1:1113, L, {69f92d44-54ab-4643-b540-23f89b796fcf}] failed. Error: ConnectionRefused. [08,07:28:48.703,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': enqueueing message EventStore.ClientAPI.Internal.TcpConnectionClosedMessage.. [08,07:28:48.704,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': TCP connection to [127.0.0.1:1113, L, {69f92d44-54ab-4643-b540-23f89b796fcf}] closed.. [06,07:28:48.924,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': TimerTick checking reconnection.... [06,07:28:49.213,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': ExecuteOperation package WriteEvents, a301f19c-bb92-4c53-a193-3a81582a49db, Operation AppendToStreamOperation (a301f19c-bb92-4c53-a193-3a81582a49db): Stream: newstream, ExpectedVersion: -2, retry count: 0, created: 07:28:46.642, last updated: 07:28:48.935.. [06,07:28:49.229,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': DiscoverEndPoint. [06,07:28:49.230,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': enqueueing message EventStore.ClientAPI.Internal.EstablishTcpConnectionMessage.. [04,07:28:49.231,DEBUG] EventStoreConnection 'ES-90357f8a-6c79-4638-909a-142c8ddb9a8b': EstablishTcpConnection to [127.0.0.1:1113].

So this seems to say that the problem is that the port is not open, I tried disabling the firewall completelly with no luck.

  • Also when I execute the command EventStore.ClusterNode.exe --db ./db --log ./logs --dev I noticed this in the outpue:

enter image description here

If I do telnet 127.0.0.1 1113 it doesn't seem to be able to connect, but I'm not finding what's wrong. Any idea?


Solution

  • I had the exact same issue @devcrp

    • your image with "Interfaces" pointed me directly to the missing flag when you start the server.

    solution (for 20.6.0 > ) is to add this flag when starting the event store

    --enable-external-tcp
    

    I had a similar issue with the "Stream Browser" being disabled in Admin UI and it requires

    --enable-atom-pub-over-http 
    

    And I had some other issues 🤠 like not being aware of https was required to access the admin UI, http was stated in documentation and did not work (also new in 20.6.0) and how to get the config file to work (also due to an obsolete flag, ExtSecureTcpPort, in the documentation, and missing info about TrustedRootCertificatesPath)

    If you look at the rows stating "DEPRECATION WARNING" in your console after the "Interfaces" there is a hint to why atom-pub-over-http and external-tcp needs to be enabled

    Here is my console output with external-tcp and atom-pub-over-http enabled

    what you see here has nothing to do with firewalls etc, it is solely the output from event store.

    [28224, 1,22:27:51.677,INF]
    INTERFACES
    External TCP (Protobuf)
            Enabled : True
            Port    : 1113
    HTTP (AtomPub)
            Enabled : True
            Port    : 2113
    
    [28224, 1,22:27:51.678,WRN]
     DEPRECATION WARNING: AtomPub over HTTP Interface has been deprecated as of version 20.02. It is recommended to use gRPC instead.
    
    [28224, 1,22:27:51.678,WRN]
     DEPRECATION WARNING: The Legacy TCP Client Interface has been deprecated as of version 20.02. The External TCP Interface can be re-enabled with the 'EnableExternalTCP' option. It is recommended to use gRPC instead.
    

    This is my working start command (in a file called '.\eventstore start command.ps1' to make it simpler to run the server)

    screen capture of powershell file as start command

    EventStore.ClusterNode.exe --db ./db --log ./logs --config=config.yaml --enable-atom-pub-over-http --enable-external-tcp --run-projections=all --start-standard-projections=true