Handling Saga Exceptions

1,564 views
Skip to first unread message

Jose Viray

unread,
May 15, 2014, 3:52:27 PM5/15/14
to masstrans...@googlegroups.com
Is there a mechanism to hook into saga exceptions thrown by mass transit? For example if a message can't be correlated to an existing saga, mass transit throws a sagaexception and puts the message into the error queue. I was hoping that a Fault<T> would be thrown, but that doesn't appear to be the case.

My use case is specifically for Automatonymous sagas.

Chris Patterson

unread,
May 16, 2014, 10:04:33 AM5/16/14
to masstrans...@googlegroups.com
I'll double check, but I'm pretty sure exceptions from state machine event handlers end up in the error queue, and they should publish a Fault message as well.



On Thu, May 15, 2014 at 12:52 PM, Jose Viray <jrv...@gmail.com> wrote:
Is there a mechanism to hook into saga exceptions thrown by mass transit? For example if a message can't be correlated to an existing saga, mass transit throws a sagaexception and puts the message into the error queue. I was hoping that a Fault<T> would be thrown, but that doesn't appear to be the case.

My use case is specifically for Automatonymous sagas.

--
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/bf028b8e-6e1b-48d0-ad7a-6467cb4744a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jose Viray

unread,
May 16, 2014, 4:55:55 PM5/16/14
to masstrans...@googlegroups.com
If it helps, the scenario that I'm running is basically trying to start a saga with an already existing correlationid. Here is the exception that I'm trying to get Mass Transit to bubble up a fault for:

MassTransit.Exceptions.SagaException: WorkflowService.ContainerWorkflow.ContainerState Saga exception on receipt of PreProcessingMessages.ContainerFound: The message cannot be accepted by an existing saga
   at MassTransit.Saga.InitiatingSagaPolicy`2.CanUseExistingInstance(IConsumeContext`1 context) in d:\BuildAgent-02\work\aa063b4295dfc097\src\MassTransit\Saga\InitiatingSagaPolicy.cs:line 54
   at MassTransit.NHibernateIntegration.Saga.NHibernateSagaRepository`1.<GetSaga>d__c`1.MoveNext() in d:\BuildAgent-02\work\aa063b4295dfc097\src\Persistence\MassTransit.NHibernateIntegration\Saga\NHibernateSagaRepository.cs:line 98
   at Automatonymous.AutomatonymousStateMachineSagaRepository`1.<GetSaga>d__a`1.MoveNext()
   at MassTransit.Saga.Pipeline.SagaMessageSinkBase`2.<Enumerate>d__0.MoveNext() in d:\BuildAgent-02\work\aa063b4295dfc097\src\MassTransit\Saga\Pipeline\SagaMessageSinkBase.cs:line 43
   at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
   at MassTransit.Context.ServiceBusReceiveContext.<ReceiveFromEndpoint>b__0(IReceiveContext context) in d:\BuildAgent-02\work\aa063b4295dfc097\src\MassTransit\Context\ServiceBusReceiveContext.cs:line 102
   at MassTransit.Transports.Endpoint.<>c__DisplayClass9.<Receive>b__5(IReceiveContext acceptContext) in d:\BuildAgent-02\work\aa063b4295dfc097\src\MassTransit\Transports\Endpoint.cs:line 275

On Friday, May 16, 2014 8:04:33 AM UTC-6, Chris Patterson wrote:
I'll double check, but I'm pretty sure exceptions from state machine event handlers end up in the error queue, and they should publish a Fault message as well.

On Thu, May 15, 2014 at 12:52 PM, Jose Viray <jrv...@gmail.com> wrote:
Is there a mechanism to hook into saga exceptions thrown by mass transit? For example if a message can't be correlated to an existing saga, mass transit throws a sagaexception and puts the message into the error queue. I was hoping that a Fault<T> would be thrown, but that doesn't appear to be the case.

My use case is specifically for Automatonymous sagas.

--
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.
Message has been deleted

Chris Patterson

unread,
Jan 19, 2016, 1:29:56 PM1/19/16
to masstrans...@googlegroups.com
Okay, so, I dug into this and the behavior to throw an exception on a missing instance is an opt-in behavior (because the v2 code base ignored them, and this would be annoying for migrations).

To opt-in to a fault when a message is discarded due to a missing instance:

    Event(() => Stopped, x => x.OnMissingInstance(m => m.Fault()));

This will cause a fault to be published and the message to be moved to the _error queue if an existing saga instance is not present. It also makes it so that you can insert a deferred retry policy for the message into the pipeline.



On Sun, Jan 17, 2016 at 5:14 AM, Tomer Yoskovich <to...@yoskovich.com> wrote:
I'm experiencing the same issue in version 3.0.17

Chris - does an automatonymous saga publishes fault events?

Thanks


On Friday, May 16, 2014 at 11:55:55 PM UTC+3, Jose Viray wrote:
If it helps, the scenario that I'm running is basically trying to start a saga with an already existing correlationid. Here is the exception that I'm trying to get Mass Transit to bubble up a fault for:

MassTransit.Exceptions.SagaException: WorkflowService.ContainerWorkflow.ContainerState Saga exception on receipt of PreProcessingMessages.ContainerFound: The message cannot be accepted by an existing saga
   at MassTransit.Saga.InitiatingSagaPolicy`2.CanUseExistingInstance(IConsumeContext`1 context) in d:\BuildAgent-02\work\aa063b4295dfc097\src\MassTransit\Saga\InitiatingSagaPolicy.cs:line 54
   at MassTransit.NHibernateIntegration.Saga.NHibernateSagaRepository`1.<GetSaga>d__c`1.MoveNext() in d:\BuildAgent-02\work\aa063b4295dfc097\src\Persistence\MassTransit.NHibernateIntegration\Saga\NHibernateSagaRepository.cs:line 98
   at Automatonymous.AutomatonymousStateMachineSagaRepository`1.<GetSaga>d__a`1.MoveNext()
   at MassTransit.Saga.Pipeline.SagaMessageSinkBase`2.<Enumerate>d__0.MoveNext() in d:\BuildAgent-02\work\aa063b4295dfc097\src\MassTransit\Saga\Pipeline\SagaMessageSinkBase.cs:line 43
   at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__14`2.MoveNext()
   at MassTransit.Context.ServiceBusReceiveContext.<ReceiveFromEndpoint>b__0(IReceiveContext context) in d:\BuildAgent-02\work\aa063b4295dfc097\src\MassTransit\Context\ServiceBusReceiveContext.cs:line 102
   at MassTransit.Transports.Endpoint.<>c__DisplayClass9.<Receive>b__5(IReceiveContext acceptContext) in d:\BuildAgent-02\work\aa063b4295dfc097\src\MassTransit\Transports\Endpoint.cs:line 275

On Friday, May 16, 2014 8:04:33 AM UTC-6, Chris Patterson wrote:
I'll double check, but I'm pretty sure exceptions from state machine event handlers end up in the error queue, and they should publish a Fault message as well.

On Thu, May 15, 2014 at 12:52 PM, Jose Viray <jrv...@gmail.com> wrote:
Is there a mechanism to hook into saga exceptions thrown by mass transit? For example if a message can't be correlated to an existing saga, mass transit throws a sagaexception and puts the message into the error queue. I was hoping that a Fault<T> would be thrown, but that doesn't appear to be the case.

My use case is specifically for Automatonymous sagas.

--
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.

--
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.

Alexey Zimarev

unread,
Jun 17, 2016, 9:53:38 AM6/17/16
to masstransit-discuss
It would be nice to have access to the context there too since I want to inform the initiator about this failure with RespondAsync.

Chris Patterson

unread,
Jun 17, 2016, 11:29:20 AM6/17/16
to masstrans...@googlegroups.com
Oh, nice, can you put an issue describing it up so I can get to it?


--
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.

Chris Patterson

unread,
Jun 17, 2016, 3:37:13 PM6/17/16
to masstrans...@googlegroups.com
I already added an Execute/ExecuteAsync method (in addition to the existing Throw() and Discard() methods, which can be used to do whatever you want when an existing instance is missing.

Alexey Zimarev

unread,
Jun 18, 2016, 5:09:02 AM6/18/16
to masstransit-discuss
Awesome, I see the context is there as parameter, it will definitely help.

My scenario was close to simple password reset with token and expiration, implemented in a saga. When user tries to activate an expired token, saga instance cannot be found (already finalized) and we need to return a meaningful response to the sender without polluting the error queue since this is not a real error. Of course we could create a new state Expired and keep saga instance in the database forever but I don't think this is an ideal solution considering temporary nature of this object.
Reply all
Reply to author
Forward
0 new messages