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

Outbox messages are store with defferent "EndpointName" and "ActualEndpointName" #165

Closed
RomanOlegovich opened this issue Apr 29, 2022 · 23 comments
Labels
bug Something isn't working waiting Waiting for a precondition to solve this issue

Comments

@RomanOlegovich
Copy link

RomanOlegovich commented Apr 29, 2022

I expect "ActualEndpointName" equals "EndpointName" in the outbox table, but it's defferent (see screanschort).

Here outbound configuration

                        .AddOutbound<NotifyPaymentEvent>(endpoint => endpoint
                            .ProduceTo(nameof(NotifyPaymentEvent))
                            .WithKafkaKey<NotifyPaymentEvent>(envelope => envelope.Message.Id)
                            .Configure(producerConfig)
                            .SerializeAsJsonUsingNewtonsoft()
                            .ProduceToOutbox())

This seems to be the cause of the error:

fail: Silverback.Messaging.Outbound.TransactionalOutbox.OutboxWorker[1077]
      Failed to produce the message stored in the outbox. | endpointName: StudentUserPhoneDuplicateEvent, messageType: *project-name*.DrivingStartingEvent, *project-name*, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null, messageId: 1e563aad-8b99-4daa-a981-f667d507bb8a, unused1: (null), unused2: (null)
      System.InvalidOperationException: No endpoint with name 'StudentUserPhoneDuplicateEvent' could be found for a message of type '*project-name*.DrivingStartingEvent'.
         at Silverback.Messaging.Outbound.TransactionalOutbox.OutboxWorker.GetTargetEndpoint(Type messageType, String endpointName, IServiceProvider serviceProvider)
         at Silverback.Messaging.Outbound.TransactionalOutbox.OutboxWorker.ProcessMessageAsync(OutboxStoredMessage message, ConcurrentBag`1 failedMessages, IOutboxReader outboxReader, IServiceProvider serviceProvider)

image

@BEagle1984
Copy link
Owner

It looks like a possible bug, yes.

Can you please provide a full project that reproduce the issue? It's hard to figure it out without seeing the entire configuration.

@BEagle1984 BEagle1984 added the bug Something isn't working label Apr 29, 2022
@RomanOlegovich
Copy link
Author

I wrote a message but forgot to send it.
To be more clarify.
StudentPhoneDuplicateEvent and NotifyPaymentEvent are generated in one CronJob, which do:

1. Generate list of StudentPhoneDuplicateEvent 
            await SyncStudents() => {
                foreach (var addEvent in addEvents)
                    await publisher.PublishAsync(addEvent);
                outBoxDbContext.SaveChanges();
            }

2.
Generate list of NotifyPaymentEvent 
            await SyncPayments() => {
                foreach (var addEvent in addEvents)
                    await publisher.PublishAsync(addEvent);
                outBoxDbContext.SaveChanges();
            }

@RomanOlegovich
Copy link
Author

RomanOlegovich commented Apr 29, 2022

I can't provide full project, I'm not owner.
I can cut out all the pieces of code related to Silverback and paste here 😃.

If you need a full project that reproduce the issue, it will take time

@BEagle1984
Copy link
Owner

BEagle1984 commented Apr 29, 2022

It doesn't have to be the same project. Anything I can run to reproduce the issue would be enough. If I can't debug it is gonna be difficult to fix it.

@BEagle1984 BEagle1984 added the waiting Waiting for a precondition to solve this issue label Nov 1, 2022
@davimorao
Copy link

davimorao commented Feb 3, 2023

Hi, I encountered the same problem in my tests.

When sending messages of different types with ICommandPublisher or IEventPublisher in the same process, the endpoint of the first message will be replicated for the next messages in the EndpointName field when calling DbContext.SaveChangesAsync() to persist the information.

Follow the steps to reproduce:

Code:
await _command.ExecuteAsync(new ExecuteSampleCommand { Guid = Guid.NewGuid(), TransactionId = Guid.NewGuid(), Sample = new ExecuteSampleCommand.SampleDto { Name = "Test", SampleStatus = ESampleStatus.SampleStatusTwo, InternalId = 1 } });
await kafkaManagementDbContext.SaveChangesAsync();

await _command.ExecuteAsync(new ExecuteSampleCommand2 { Guid = Guid.NewGuid(), TransactionId = Guid.NewGuid(), Sample = new ExecuteSampleCommand2.SampleDto { Name = "Test", InternalId = 1 } });
await kafkaManagementDbContext.SaveChangesAsync();

The error occurs according to the code above, and will also occur if the commit in the DbContext after sending the first and second message

Database
image

@BEagle1984
Copy link
Owner

Can you provide a working project that reproduces the issue?
I'd be glad to debug it.

@davimorao
Copy link

Here's the sample project, let me know if I need more info, thanks.

https://github.com/davimorao/poc-silverback-outbox

@alefcarlos
Copy link

@BEagle1984 are you good ?

Any news about that issue ? Or any advice how could we workaround that behaviour?

@BEagle1984
Copy link
Owner

I unfortunately didn't have time to debug this issue yet.

An obvious workaround would be to not use the outbox but I guess it's not an option for you.

@alefcarlos
Copy link

@BEagle1984 , dont you use outbox in production ?

@BEagle1984
Copy link
Owner

Not me personally, as I don't have the need in my current projects. But some colleagues do and I never heard of this issue. Maybe different version, different circumstances, etc.

@cookie-bytes
Copy link
Contributor

cookie-bytes commented Feb 18, 2023

In OutboxProduceStrategyImplementation I think trying to cache the IProducer is causing the issue.
If I change "ProduceAsync" to the following the endpoint is configured correctly in the outbox table.

        public Task ProduceAsync(IOutboundEnvelope envelope)
        {
            Check.NotNull(envelope, nameof(envelope));

            _logger.LogWrittenToOutbox(envelope);

            if (_producer == null || _producer.Endpoint.Name != envelope.Endpoint.Name)
            {
                _producer = _outboundQueueBroker.GetProducer(envelope.Endpoint);
            }
            return _producer.ProduceAsync(envelope);
        }

Does this fix sound reasonable?

Thanks

@BEagle1984
Copy link
Owner

I'm very sorry, I didn't have time yet to look deeply into the issue.

Your explanation makes sense and the fix seems indeed reasonable. Pack it into a PR. 🙂

Thanks a lot! 😎

@cookie-bytes
Copy link
Contributor

cookie-bytes commented Feb 20, 2023

@BEagle1984 I have created a PR, but the pipeline is failing on a test. I can't get this test to fail locally. Any ideas?

https://github.com/BEagle1984/silverback/pull/188/checks?check_run_id=11459889363

@BEagle1984
Copy link
Owner

It's ok, it's probably flaky on the pipeline. I'm trying to make the tests more reliable but most of the improvements have been implemented for the upcoming big release and not back ported to the current one (in master). I'm checking your pr.

BEagle1984 pushed a commit that referenced this issue Feb 21, 2023
@BEagle1984
Copy link
Owner

BEagle1984 commented Feb 21, 2023

I'm still trying to figure out what happened with the test but I uploaded a version (v4.1.1-beta.1) to nuget.org which includes this PR.
Do you guys have the possibility to test it?

@cookie-bytes
Copy link
Contributor

Yes, we will update to the new package tomorrow and start our tests. Thank you

@davimorao
Copy link

Here's the sample project, let me know if I need more info, thanks.

https://github.com/davimorao/poc-silverback-outbox

Hello everyone, I did a test regarding the scenario of this example and messages of different types were stored, sent and consumed correctly.

@alefcarlos
Copy link

@BEagle1984 when are you planning to release the final version of 4.1.1 ? Currently its 4.1.1-beta.1.

@BEagle1984
Copy link
Owner

I will release this weekend or at the beginning of next week. Did you try the beta @alefcarlos ?

@alefcarlos
Copy link

@BEagle1984, @davimorao and I work together rs

We tried the beta and everything worked good!

@cookie-bytes did you try that?

@cookie-bytes
Copy link
Contributor

Yes, tested and working as expected. It has not been through performance testing though.

@BEagle1984
Copy link
Owner

Published v4.1.1 including the fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting Waiting for a precondition to solve this issue
Projects
None yet
Development

No branches or pull requests

5 participants