entity framework saga persistence

905 views
Skip to first unread message

Jeff Posey

unread,
Mar 3, 2016, 1:34:04 PM3/3/16
to masstransit-discuss
I'm trying to use the EntityFrameworkSagaRepository and when I run single instances of the saga I can see the sagas persisting and completing. If I do many I start getting the following error:

System.Data.Entity.Core.EntityException: The underlying provider failed on Rollback. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: connection

any ideas why?

Sergii K

unread,
Mar 21, 2016, 4:32:53 PM3/21/16
to masstransit-discuss
I had similar exception message. In my case it was because of transaction deadlock. It may happen, for example, when you using saga which CorrelationId correlates with some message property (like EntityId) and two message with same property value were received simultaneously.
 
четверг, 3 марта 2016 г., 20:34:04 UTC+2 пользователь Jeff Posey написал:

Chris Patterson

unread,
Mar 21, 2016, 5:24:39 PM3/21/16
to masstrans...@googlegroups.com
I actually thought this was fixed, because of the way EF discards "unsaved changes." Are you on a current version of MT?


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/8503ac10-3fae-468c-9f6e-6705fb5870bd%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Dmitry Mikhaylov

unread,
Apr 5, 2016, 9:26:35 AM4/5/16
to masstransit-discuss
Hi,

I see same issue running saga consumer with 10 items in queue. It is actually topic not a queue with Azure Service Bus. When saga start processing those messages in happened to persist 3 of 10.
MassTransit version 3.2.4.

Please advise for solution here.

On Monday, 21 March 2016 23:24:39 UTC+2, Chris Patterson wrote:
I actually thought this was fixed, because of the way EF discards "unsaved changes." Are you on a current version of MT?

On Mon, Mar 21, 2016 at 1:32 PM, Sergii K <serg.c...@gmail.com> wrote:
I had similar exception message. In my case it was because of transaction deadlock. It may happen, for example, when you using saga which CorrelationId correlates with some message property (like EntityId) and two message with same property value were received simultaneously.
 
четверг, 3 марта 2016 г., 20:34:04 UTC+2 пользователь Jeff Posey написал:
I'm trying to use the EntityFrameworkSagaRepository and when I run single instances of the saga I can see the sagas persisting and completing. If I do many I start getting the following error:

System.Data.Entity.Core.EntityException: The underlying provider failed on Rollback. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: connection

any ideas why?

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

Dmitry Mikhaylov

unread,
Apr 5, 2016, 12:21:30 PM4/5/16
to masstransit-discuss
Looks like if I specify isolation level creating repository the issue is gone. I set Isolation Level RepeatableRead for now. Will check would Serializable do the same thing.

Chris Patterson

unread,
Apr 5, 2016, 1:29:15 PM4/5/16
to masstrans...@googlegroups.com
For sagas, serializable should always be used. This needs to be documented, as it's apparently only shown in the samples.


On Tue, Apr 5, 2016 at 9:21 AM, Dmitry Mikhaylov <dmitry.pyroj...@gmail.com> wrote:
Looks like if I specify isolation level creating repository the issue is gone. I set Isolation Level RepeatableRead for now. Will check would Serializable do the same thing.


On Tuesday, 5 April 2016 16:26:35 UTC+3, Dmitry Mikhaylov wrote:
Hi,

I see same issue running saga consumer with 10 items in queue. It is actually topic not a queue with Azure Service Bus. When saga start processing those messages in happened to persist 3 of 10.
MassTransit version 3.2.4.

Please advise for solution here.

On Monday, 21 March 2016 23:24:39 UTC+2, Chris Patterson wrote:
I actually thought this was fixed, because of the way EF discards "unsaved changes." Are you on a current version of MT?

On Mon, Mar 21, 2016 at 1:32 PM, Sergii K <serg.c...@gmail.com> wrote:
I had similar exception message. In my case it was because of transaction deadlock. It may happen, for example, when you using saga which CorrelationId correlates with some message property (like EntityId) and two message with same property value were received simultaneously.
 
четверг, 3 марта 2016 г., 20:34:04 UTC+2 пользователь Jeff Posey написал:
I'm trying to use the EntityFrameworkSagaRepository and when I run single instances of the saga I can see the sagas persisting and completing. If I do many I start getting the following error:

System.Data.Entity.Core.EntityException: The underlying provider failed on Rollback. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: connection

any ideas why?

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

Dmitry Mikhaylov

unread,
Apr 5, 2016, 4:24:14 PM4/5/16
to masstransit-discuss
With serializable I get the rollback error. Looks like EF transaction is shared across concurrent calls and gets messed up. Trying to find solution.


On Tuesday, 5 April 2016 20:29:15 UTC+3, Chris Patterson wrote:
For sagas, serializable should always be used. This needs to be documented, as it's apparently only shown in the samples.

On Tue, Apr 5, 2016 at 9:21 AM, Dmitry Mikhaylov <dmitry.pyroj...@gmail.com> wrote:
Looks like if I specify isolation level creating repository the issue is gone. I set Isolation Level RepeatableRead for now. Will check would Serializable do the same thing.


On Tuesday, 5 April 2016 16:26:35 UTC+3, Dmitry Mikhaylov wrote:
Hi,

I see same issue running saga consumer with 10 items in queue. It is actually topic not a queue with Azure Service Bus. When saga start processing those messages in happened to persist 3 of 10.
MassTransit version 3.2.4.

Please advise for solution here.

On Monday, 21 March 2016 23:24:39 UTC+2, Chris Patterson wrote:
I actually thought this was fixed, because of the way EF discards "unsaved changes." Are you on a current version of MT?

On Mon, Mar 21, 2016 at 1:32 PM, Sergii K <serg.c...@gmail.com> wrote:
I had similar exception message. In my case it was because of transaction deadlock. It may happen, for example, when you using saga which CorrelationId correlates with some message property (like EntityId) and two message with same property value were received simultaneously.
 
четверг, 3 марта 2016 г., 20:34:04 UTC+2 пользователь Jeff Posey написал:
I'm trying to use the EntityFrameworkSagaRepository and when I run single instances of the saga I can see the sagas persisting and completing. If I do many I start getting the following error:

System.Data.Entity.Core.EntityException: The underlying provider failed on Rollback. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: connection

any ideas why?

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

Chris Patterson

unread,
Apr 5, 2016, 4:29:13 PM4/5/16
to masstrans...@googlegroups.com
That would be a strange case of sharing a DbContext, versus providing a separate DbContext for each message. The DbContext cannot be shared, if I recall my understanding of how EF works.


On Tue, Apr 5, 2016 at 1:24 PM, Dmitry Mikhaylov <dmitry.pyroj...@gmail.com> wrote:
With serializable I get the rollback error. Looks like EF transaction is shared across concurrent calls and gets messed up. Trying to find solution.

On Tuesday, 5 April 2016 20:29:15 UTC+3, Chris Patterson wrote:
For sagas, serializable should always be used. This needs to be documented, as it's apparently only shown in the samples.

On Tue, Apr 5, 2016 at 9:21 AM, Dmitry Mikhaylov <dmitry.pyroj...@gmail.com> wrote:
Looks like if I specify isolation level creating repository the issue is gone. I set Isolation Level RepeatableRead for now. Will check would Serializable do the same thing.


On Tuesday, 5 April 2016 16:26:35 UTC+3, Dmitry Mikhaylov wrote:
Hi,

I see same issue running saga consumer with 10 items in queue. It is actually topic not a queue with Azure Service Bus. When saga start processing those messages in happened to persist 3 of 10.
MassTransit version 3.2.4.

Please advise for solution here.

On Monday, 21 March 2016 23:24:39 UTC+2, Chris Patterson wrote:
I actually thought this was fixed, because of the way EF discards "unsaved changes." Are you on a current version of MT?

On Mon, Mar 21, 2016 at 1:32 PM, Sergii K <serg.c...@gmail.com> wrote:
I had similar exception message. In my case it was because of transaction deadlock. It may happen, for example, when you using saga which CorrelationId correlates with some message property (like EntityId) and two message with same property value were received simultaneously.
 
четверг, 3 марта 2016 г., 20:34:04 UTC+2 пользователь Jeff Posey написал:
I'm trying to use the EntityFrameworkSagaRepository and when I run single instances of the saga I can see the sagas persisting and completing. If I do many I start getting the following error:

System.Data.Entity.Core.EntityException: The underlying provider failed on Rollback. ---> System.ArgumentNullException: Value cannot be null.
Parameter name: connection

any ideas why?

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

Dmitry Mikhaylov

unread,
Apr 5, 2016, 4:38:33 PM4/5/16
to masstransit-discuss
You're right. DbContext must not be shared in multi threaded environment. And I see that db context created by from SagaDbFactory, it is wrapped by using statement.
However transaction scope that is created out of the context might be shared by local DTC. Not sure is it the case, though. 

BTW, I'm using localdb at this moment for persistence.

Dmitry Mikhaylov

unread,
Apr 6, 2016, 4:37:37 AM4/6/16
to masstransit-discuss
Don't think that my idea from previous post is correct...

I took EntityFrameworkSagaRepository, added as custom one to my project for debugging purpose, customized it not to be generic, and found the the issue is no longer reproducible.

Chris, you said that you fixed that previous, can you please give a hint where is the code that you changed for the fix.

Thank you,
Dmytro

Dmitry Mikhaylov

unread,
Apr 6, 2016, 6:57:05 AM4/6/16
to masstransit-discuss
Hello,

Apparently I have not got to the bottom of this. My latest progress, that with same code and IsolationLevel.Serializable I have connection closed in underlying transaction on Rollback.
Playing around with code, changing awaiting there found that if I get rid of await on policy.Missing and use "policy.Missing(context, missingSagaPipe).Wait()" (EntityFrameworkSagaRepository.cs Line: 166), I can keep isolation level and don't have error on rollback.

That gives performance penalty, but I get more reliable code now.

Will keep you posted on my research here.

If I get a free minute, I'll do sample isolated app for reproducing. Let me know if you're interesting in it.

Regards,
Dmytro

Chris Patterson

unread,
Apr 6, 2016, 6:21:33 PM4/6/16
to masstrans...@googlegroups.com
It really sounds like you're sharing a DbContext, and not creating a unique one for the saga repository to use for each message.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Dmitry Mikhaylov

unread,
Apr 7, 2016, 12:18:10 PM4/7/16
to masstransit-discuss
I'm using SagaDbFactory and EntityFrameworkSagaRepository. I see that the repository creates new context using the factory.


On Thursday, 7 April 2016 01:21:33 UTC+3, Chris Patterson wrote:
It really sounds like you're sharing a DbContext, and not creating a unique one for the saga repository to use for each message.
On Wed, Apr 6, 2016 at 5:57 AM, Dmitry Mikhaylov <dmitry.pyroj...@gmail.com> wrote:
Hello,

Apparently I have not got to the bottom of this. My latest progress, that with same code and IsolationLevel.Serializable I have connection closed in underlying transaction on Rollback.
Playing around with code, changing awaiting there found that if I get rid of await on policy.Missing and use "policy.Missing(context, missingSagaPipe).Wait()" (EntityFrameworkSagaRepository.cs Line: 166), I can keep isolation level and don't have error on rollback.

That gives performance penalty, but I get more reliable code now.

Will keep you posted on my research here.

If I get a free minute, I'll do sample isolated app for reproducing. Let me know if you're interesting in it.

Regards,
Dmytro

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

Chris Patterson

unread,
Apr 7, 2016, 1:50:18 PM4/7/16
to masstrans...@googlegroups.com
A standalone reproducible test would really help here, as I can't seem to recreate it myself.

On Thu, Apr 7, 2016 at 11:18 AM, Dmitry Mikhaylov <dmitry.pyroj...@gmail.com> wrote:
I'm using SagaDbFactory and EntityFrameworkSagaRepository. I see that the repository creates new context using the factory.

On Thursday, 7 April 2016 01:21:33 UTC+3, Chris Patterson wrote:
It really sounds like you're sharing a DbContext, and not creating a unique one for the saga repository to use for each message.
On Wed, Apr 6, 2016 at 5:57 AM, Dmitry Mikhaylov <dmitry.pyroj...@gmail.com> wrote:
Hello,

Apparently I have not got to the bottom of this. My latest progress, that with same code and IsolationLevel.Serializable I have connection closed in underlying transaction on Rollback.
Playing around with code, changing awaiting there found that if I get rid of await on policy.Missing and use "policy.Missing(context, missingSagaPipe).Wait()" (EntityFrameworkSagaRepository.cs Line: 166), I can keep isolation level and don't have error on rollback.

That gives performance penalty, but I get more reliable code now.

Will keep you posted on my research here.

If I get a free minute, I'll do sample isolated app for reproducing. Let me know if you're interesting in it.

Regards,
Dmytro

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

Dmitry Mikhaylov

unread,
Apr 7, 2016, 5:10:56 PM4/7/16
to masstransit-discuss
Hello Chris,

I've put together some test code that I can reproduce the issue with. You can find it here: https://github.com/PyroJoke/mt-ef-issue

The code pre-populates queue with 50 messages and then starts receiving endpoint.
With that setup, DB actually get's about 20 saga instances created others fails on rollback.

Hope this would help.

Best Regards,
Dmytro

Chris Patterson

unread,
Apr 7, 2016, 6:51:00 PM4/7/16
to masstrans...@googlegroups.com
Perfect, that was the trick, queuing them up. I'll pull it down and try to fix it shortly.


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Dmitry Mikhaylov

unread,
Apr 15, 2016, 10:03:37 AM4/15/16
to masstransit-discuss
Hi,

Have you got chance to check the issue?

Chris Patterson

unread,
Apr 15, 2016, 2:21:03 PM4/15/16
to masstrans...@googlegroups.com
Yeah, and I have a fix that works. I think I pushed it to develop, I'll have to verify.



--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Dmitry Mikhaylov

unread,
Apr 16, 2016, 12:30:46 PM4/16/16
to masstransit-discuss
Cool! Thanks!

I will check it with our code and let you know about the result.

Chris Patterson

unread,
Apr 16, 2016, 3:55:43 PM4/16/16
to masstrans...@googlegroups.com
That would be helpful to make sure it's resolved. 

__
Chris Patterson




--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Jonathan Wong

unread,
Aug 4, 2016, 3:30:06 PM8/4/16
to masstransit-discuss
I built the develop branch (commit 9af2226) and still got the rollback issue. Can anyone else reproduce or verify the fix?


On Saturday, April 16, 2016 at 12:55:43 PM UTC-7, Chris Patterson wrote:
That would be helpful to make sure it's resolved. 

__
Chris Patterson




On Sat, Apr 16, 2016 at 9:30 AM -0700, "Dmitry Mikhaylov" <dmitry.pyroj...@gmail.com> wrote:

Cool! Thanks!

I will check it with our code and let you know about the result.

On Friday, 15 April 2016 21:21:03 UTC+3, Chris Patterson wrote:
Yeah, and I have a fix that works. I think I pushed it to develop, I'll have to verify.



On Fri, Apr 15, 2016 at 7:03 AM, Dmitry Mikhaylov <dmitry.pyroj...@gmail.com> wrote:
Hi,

Have you got chance to check the issue?


On Friday, 8 April 2016 01:51:00 UTC+3, Chris Patterson wrote:
Perfect, that was the trick, queuing them up. I'll pull it down and try to fix it shortly.


-- 

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages