Eventuous / eventuous

Event Sourcing library for .NET
https://eventuous.dev
Apache License 2.0
430 stars 69 forks source link

"Can not start an Activity that was already started" in BaseProducer #327

Closed gius closed 1 month ago

gius commented 3 months ago

Describe the bug When producing an event, System.InvalidOperationException: '"Can not start an Activity that was already started"' is thrown (and immediately swallowed) by System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.Activity.NotifyError(System.Exception exception).

The reason is that in BaseProducer.Produce, we explicitly call act?.Start(), but the activity has already been started by the previous line's call to ProducerActivity.Start.

https://github.com/Eventuous/eventuous/blob/b72c9c0d9115c4a25572e6277c54a940e4b5b9b0/src/Core/src/Eventuous.Producers/BaseProducer.cs#L46-L47

To Reproduce Steps to reproduce the behavior:

  1. Enable Break When Thrown for System.InvalidOperationException in Visual Studio's Exception Settings
  2. Publish an event through RabbitMqProducer
  3. See error

Expected behavior No exception should be thrown.

I can provide a PR if you want. As far as I can understand, simply changing https://github.com/Eventuous/eventuous/blob/b72c9c0d9115c4a25572e6277c54a940e4b5b9b0/src/Core/src/Eventuous.Producers/BaseProducer.cs#L47 to return (act, new[] { producedMessage }); should be enough.