I have the following sessionBound class

public class GlobalBrokerDispatcher : SessionBound {

        static string ApplicationName = ConfigurationSettings.AppSettings.Get("nnet.application.name");

        public GlobalBrokerDispatcher(Session session) : base(session) {
        }

        [MessageConsumer]
        public void FiringEvent(FiringEvent firingEvent) {
            try {
                var subscriptionTopic = (from topic in Query<Topic>.All where topic.Name == firingEvent.EventTopic.Uri select topic).SingleOrDefault<Topic>();
                if (subscriptionTopic == null) {
                    subscriptionTopic = new Topic { Name = firingEvent.EventTopic.Uri };
                }
                var topicEvent = new Event();
                topicEvent.ApplicationName = ApplicationName;
                if (firingEvent.E != null) topicEvent.setEventArgs(firingEvent.E);
                subscriptionTopic.Events.Add(topicEvent);
            } catch (Exception ex) {
                Console.WriteLine("FiringEvent Error : " + ex.ToString()+ex.StackTrace);
            }
        }
    }

Works ok most of the time but occasionally the line subscriptionTopic.Events.Add(topicEvent); throws the following error,any ideas

FiringEvent Error : System.InvalidOperationException: Transaction is not open.
   at Xtensive.Storage.Providers.Sql.SessionHandler.EnsureAutoShortenTransactionIsStarted() in c:\TeamCity\buildAgent\work\6a5d813
09423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\SessionHandler.cs:line 273
   at Xtensive.Storage.Providers.Sql.SessionHandler.<ExecuteTupleReader>d__0.MoveNext() in c:\TeamCity\buildAgent\work\6a5d8130942
3096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\SessionHandler.cs:line 130
   at Xtensive.Storage.Providers.Sql.SqlProvider.<OnEnumerate>d__0.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xten
sive.Storage\Xtensive.Storage.Providers.Sql\SqlProvider.cs:line 48
   at Xtensive.Storage.Rse.Providers.ExecutableProvider.<GetEnumerator>d__0.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423
096e\Xtensive.Storage\Xtensive.Storage.Rse\Providers\ExecutableProvider.cs:line 215
   at Xtensive.Core.Collections.EnumerableExtensions.<Batch>d__27`1.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xte
nsive.Core\Xtensive.Core\Collections\EnumerableExtensions.cs:line 483
   at Xtensive.Core.Collections.EnumerableExtensions.<ApplyBeforeAndAfter>d__2f`1.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81
309423096e\Xtensive.Core\Xtensive.Core\Collections\EnumerableExtensions.cs:line 579
   at Xtensive.Storage.Rse.RecordSet.<GetEnumerator>d__4.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Stora
ge\Xtensive.Storage.Rse\RecordSet.cs:line 71
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Xtensive.Core.Collections.EnumerableExtensions.<Batch>d__27`1.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xte
nsive.Core\Xtensive.Core\Collections\EnumerableExtensions.cs:line 483
   at Xtensive.Core.Collections.EnumerableExtensions.<ApplyBeforeAndAfter>d__2f`1.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81
309423096e\Xtensive.Core\Xtensive.Core\Collections\EnumerableExtensions.cs:line 579
   at Xtensive.Storage.Linq.Materialization.MaterializationHelper.<Materialize>d__8`1.MoveNext() in c:\TeamCity\buildAgent\work\6a
5d81309423096e\Xtensive.Storage\Xtensive.Storage\Linq\Materialization\MaterializationHelper.cs:line 97
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at lambda_method(ExecutionScope , Object[] , IEnumerable`1 , Dictionary`2 )
   at Xtensive.Core.Helpers.DelegateBindExtensions.<>c__DisplayClassa`4.<Bind>b__9(T2 arg2, T3 arg3) in c:\TeamCity\buildAgent\wor
k\6a5d81309423096e\Xtensive.Core\Xtensive.Core\Helpers\DelegateBindExtensions.cs:line 46
   at Xtensive.Storage.Linq.TranslatedQuery`1.Execute() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.
Storage\Linq\TranslatedQuery{TResult}.cs:line 32
   at Xtensive.Storage.Linq.QueryProvider.Execute[TResult](Expression expression) in c:\TeamCity\buildAgent\work\6a5d81309423096e\
Xtensive.Storage\Xtensive.Storage\Linq\QueryProvider.cs:line 59
   at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source)
   at NNet.Broker.Extensions.GlobalBrokerDispatcher.FiringEvent(FiringEvent firingEvent) in D:\Project\Broker\EventBroker\Extensio
ns\GlobalBrokerExtension.cs:line 41   at Xtensive.Storage.Providers.Sql.SessionHandler.EnsureAutoShortenTransactionIsStarted() in
c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\SessionHandler.cs:line 273
   at Xtensive.Storage.Providers.Sql.SessionHandler.<ExecuteTupleReader>d__0.MoveNext() in c:\TeamCity\buildAgent\work\6a5d8130942
3096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\SessionHandler.cs:line 130
   at Xtensive.Storage.Providers.Sql.SqlProvider.<OnEnumerate>d__0.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xten
sive.Storage\Xtensive.Storage.Providers.Sql\SqlProvider.cs:line 48
   at Xtensive.Storage.Rse.Providers.ExecutableProvider.<GetEnumerator>d__0.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423
096e\Xtensive.Storage\Xtensive.Storage.Rse\Providers\ExecutableProvider.cs:line 215
   at Xtensive.Core.Collections.EnumerableExtensions.<Batch>d__27`1.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xte
nsive.Core\Xtensive.Core\Collections\EnumerableExtensions.cs:line 483
   at Xtensive.Core.Collections.EnumerableExtensions.<ApplyBeforeAndAfter>d__2f`1.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81
309423096e\Xtensive.Core\Xtensive.Core\Collections\EnumerableExtensions.cs:line 579
   at Xtensive.Storage.Rse.RecordSet.<GetEnumerator>d__4.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Stora
ge\Xtensive.Storage.Rse\RecordSet.cs:line 71
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Xtensive.Core.Collections.EnumerableExtensions.<Batch>d__27`1.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xte
nsive.Core\Xtensive.Core\Collections\EnumerableExtensions.cs:line 483
   at Xtensive.Core.Collections.EnumerableExtensions.<ApplyBeforeAndAfter>d__2f`1.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81
309423096e\Xtensive.Core\Xtensive.Core\Collections\EnumerableExtensions.cs:line 579
   at Xtensive.Storage.Linq.Materialization.MaterializationHelper.<Materialize>d__8`1.MoveNext() in c:\TeamCity\buildAgent\work\6a
5d81309423096e\Xtensive.Storage\Xtensive.Storage\Linq\Materialization\MaterializationHelper.cs:line 97
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at lambda_method(ExecutionScope , Object[] , IEnumerable`1 , Dictionary`2 )
   at Xtensive.Core.Helpers.DelegateBindExtensions.<>c__DisplayClassa`4.<Bind>b__9(T2 arg2, T3 arg3) in c:\TeamCity\buildAgent\wor
k\6a5d81309423096e\Xtensive.Core\Xtensive.Core\Helpers\DelegateBindExtensions.cs:line 46
   at Xtensive.Storage.Linq.TranslatedQuery`1.Execute() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.
Storage\Linq\TranslatedQuery{TResult}.cs:line 32
   at Xtensive.Storage.Linq.QueryProvider.Execute[TResult](Expression expression) in c:\TeamCity\buildAgent\work\6a5d81309423096e\
Xtensive.Storage\Xtensive.Storage\Linq\QueryProvider.cs:line 59
   at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source)
   at NNet.Broker.Extensions.GlobalBrokerDispatcher.FiringEvent(FiringEvent firingEvent) in D:\Project\Broker\EventBroker\Extensio
ns\GlobalBrokerExtension.cs:line 41

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Dec 18 '09 at 13:49

Tony's gravatar image

Tony
53262628


One Answer:

Alex Kofman wrote:

Could you check whether a transaction is open before calling subscriptionTopic.Events.Add(topicEvent) method, when such exception is thrown.

To do this modify your code as shown below:

[MessageConsumer]
        public void FiringEvent(FiringEvent firingEvent) 
        {
            bool transactionIsOpen = Session.Transaction!=null &&
                 Session.Transaction.State==Integrity.Transactions.TransactionState.Active;
            try {

                ...
            } 
            catch (Exception ex) {
                Console.WriteLine("FiringEvent Error: '{0}', Transacion is open: {1}, Stack trace: {2}", 
                     ex.Message, transactionIsOpen, ex.StackTrace);
            }
        }

Alex (Xtensive) wrote:

Alex, it seems the code is correct, since FiringEvent is SessionBound method, so it should open a transaction by its own.

I suspect there is something with AutoShortenTransaction option handling or batching. I'll ask the guy that knows this part best to study this.

answered Dec 18 '09 at 14:26

Editor's gravatar image

Editor
46154156157

Alex Kofman wrote: By the way, It seems you have an exception when SingleOrDefault() is executed, but not in subscriptionTopic.Events.Add(topicEvent). I.e. transaction is just not open when you call FiringEvent method.

(Dec 18 '09 at 14:26) Editor Editor's gravatar image

Denis Krjuchkov, the guy responsible for this, found that you're using ~ v4.0.5 by stack trace - so most likely, the issue is already fixed in the latest nightly build. I'm going to publish v4.1 RC2 during next few days, so just download and install it.

(Dec 18 '09 at 14:26) Alex Yakunin Alex%20Yakunin's gravatar image

Tony wrote: Thanks I'll give that a try.

(Dec 18 '09 at 14:26) Editor Editor's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×573

Asked: Dec 18 '09 at 13:49

Seen: 3,611 times

Last updated: Dec 18 '09 at 13:49

powered by OSQA