EventstoreDb -- AppendToStreamAsync "hangs". Why?

Viewed 185

I'm trying to implement a repository based on eventstore, eventstore.com. The Eventstore is running -- attempted -- plain vanilla from my docker for windows. I'm loosely following the video here: https://www.youtube.com/watch?v=Sopi-gI5qKU

Now, my call to AppendToStreamAsync just hangs. I don't understand why. What am I doing wrong?

Docker:

[ 1,12,10:25:43.886,INF] Connection '"external-normal"""' ["172.18.0.1:49020", {508e83cf-f221-4627-84a0-7c32265ee51d}] closed: Success.

[ 1,58,10:25:43.886,DBG] Persistent subscription lost connection from "172.18.0.1:49020"

[ 1,58,10:25:44.083,INF] External TCP connection accepted: [Normal, "172.18.0.1:49024", L"172.18.0.3:1113", {9b21e221-ea26-43a0-889b-a01f8ee14929}].

[ 1,58,10:25:45.254,INF] ES "TcpConnection" closed [10:25:45.254: N"172.18.0.1:49024", L"172.18.0.3:1113", {9b21e221-ea26-43a0-889b-a01f8ee14929}]:Received bytes: 153, Sent bytes: 0

[ 1,58,10:25:45.254,INF] ES "TcpConnection" closed [10:25:45.254: N"172.18.0.1:49024", L"172.18.0.3:1113", {9b21e221-ea26-43a0-889b-a01f8ee14929}]:Send calls: 0, callbacks: 0

[ 1,58,10:25:45.254,INF] ES "TcpConnection" closed [10:25:45.254: N"172.18.0.1:49024", L"172.18.0.3:1113", {9b21e221-ea26-43a0-889b-a01f8ee14929}]:Receive calls: 2, callbacks: 2

[ 1,58,10:25:45.254,INF] ES "TcpConnection" closed [10:25:45.254: N"172.18.0.1:49024", L"172.18.0.3:1113", {9b21e221-ea26-43a0-889b-a01f8ee14929}]:Close reason: [Success] "Socket closed"

[ 1,58,10:25:45.255,INF] Connection '"external-normal"""' ["172.18.0.1:49024", {9b21e221-ea26-43a0-889b-a01f8ee14929}] closed: Success.

[ 1,58,10:25:45.255,DBG] Persistent subscription lost connection from "172.18.0.1:49024"

https://github.com/AndersJuul/GameHall/blob/main/GameHall.SharedKernel.Tests/IntegrationTests/DataStorage/EventStoreRepositoryTests.cs

[Fact(Timeout = 20000)]
public async Task ThatStoredEventsCanBeRehydrated()
{
    var settings = ConnectionSettings.Create()
        .KeepReconnecting()
        .SetGossipTimeout(TimeSpan.FromMilliseconds(500))
        .SetGossipSeedEndPoints(
            new IPEndPoint(IPAddress.Loopback, 2113)
        )
        .SetDefaultUserCredentials(new UserCredentials("admin", "changeit"));
    var connection = EventStoreConnection.Create(settings, new IPEndPoint(IPAddress.Loopback, 1113));
    await connection.ConnectAsync();

    var aggregateId = Guid.NewGuid();
    var list = new List<IEvent>()
    {
        new AccountCreatedEvent(aggregateId, "Eric"),
        new FundsDepositedEvent(aggregateId, 150),
        new FundsDepositedEvent(aggregateId, 100),
        new FundsWithdrawnEvent(aggregateId, 25),
    };

    foreach (var ev in list)
    {
        var json = JsonConvert.SerializeObject(ev,
            new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.None});
        var payload = Encoding.UTF8.GetBytes(json);
        var eventStoreDataType = new EventData(Guid.NewGuid(), ev.GetType().Name, true, payload, null);
        await connection.AppendToStreamAsync(Infrastructure.DataStorage.EventStore.StreamId(aggregateId),
            ExpectedVersion.Any, eventStoreDataType);
    }
1 Answers

Although you are running ESDB in insecure mode, the client by default tried to connect with TLS over TCP, and fails.

You can simply connect using this line, and it will work:

var connection = 
    EventStoreConnection.Create(
        "ConnectTo=tcp://localhost:1113; UseSslConnection=false;"
    );

Remember that TCP protocol is legacy, and will be phased out at some point. I strongly recommend using the gRPC client only.

Related