Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception calling AppendToStreamAsync with duplicate event #247

Open
StevenBlair123 opened this issue Apr 3, 2023 · 2 comments
Open

Exception calling AppendToStreamAsync with duplicate event #247

StevenBlair123 opened this issue Apr 3, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@StevenBlair123
Copy link

Describe the bug
After writing an event to the database, we truncate the stream, then attempt to write the same event to the stream.
An exception is thrown on the second AppendToStreamAsync call.

To Reproduce
Steps to reproduce the behavior:

  1. Write Event to Stream1
  2. Delete the Stream
  3. Write Event to Stream1

Expected behavior
No Error should be thrown.

Actual behavior
Exception is thrown:

Grpc.Core.RpcException : Status(StatusCode="Unknown", Detail="Exception was thrown by handler.")

Config/Logs/Screenshots
If applicable, please attach your node configuration, logs or any screenshots.

EventStore details

  • EventStore server version: 22.10

  • Operating system: Windows

  • EventStore client version (if applicable): 23.0

Additional context

I have included my unit test incase it's something in the test that wrong:

[Test]
 public async Task truncated_stream_can_be_written_to(){
     String eventStoreConnectionString = ConfigurationReader.GetValue(Constants.KeyNameEventStoreConnectionString);
     EventStoreClientSettings eventStoreClientSettings = EventStoreClientSettings.Create(eventStoreConnectionString);

     eventStoreClientSettings.OperationOptions = new EventStoreClientOperationOptions(){
                                                                                           ThrowOnAppendFailure = false
                                                                                       };

     EventStoreClient eventStoreClient = new(eventStoreClientSettings);
     String streamName = $"TestStream{Guid.NewGuid():N}";

     EventData GetEvent(){
         var @event1 = new{
                              EventId = Guid.Parse("da3a18fe-74ae-4751-b97e-fd711fef260c"),
                              Id = 1,
                              Type = "TestEvent"
                          };

         Byte[] bytes = Encoding.Default.GetBytes(JsonConvert.SerializeObject(@event1));
         return   new(Uuid.FromGuid(@event1.EventId), @event1.Type, (ReadOnlyMemory<Byte>)bytes);
     }

     await eventStoreClient.AppendToStreamAsync(streamName, StreamState.NoStream, new []{ GetEvent() });

     //Truncate the stream
     DeleteResult deleteResult = await eventStoreClient.DeleteAsync(streamName, StreamState.StreamExists);

     //Get the events
     EventStoreClient.ReadStreamResult result = eventStoreClient.ReadStreamAsync(Direction.Backwards, streamName, StreamPosition.Start);

     ReadState readState = await result.ReadState;

     readState.ShouldBe(ReadState.StreamNotFound);

     IWriteResult r = await eventStoreClient.AppendToStreamAsync(streamName, 
                                                                 StreamState.Any, 
                                                                 new[] { GetEvent() },
                                                                 ConfigureOperationOptions);
 }
@alexeyzimarev
Copy link
Member

Have you seen anything on the server side? From the error message I'd expect an errors in the server logs.

@StevenBlair123
Copy link
Author

[ 1,12,15:45:20.256,DBG] IDEMPOTENT WRITE TO STREAM ClientCorrelationID c1321167-af19-4c91-a983-e2e7c5181757, "EventStreamId: TestStream1617ff842b064cbc98023c9a4e17f2a5, CorrelationId: c6d3dea6-9765-4d38-9576-f2fd38ea81ea, FirstEventNumber: 0, LastEventNumber: 0".

@hayley-jean hayley-jean added the bug Something isn't working label Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants