locked
Getting a SessionLockLostException when trying to complete a message RRS feed

  • Question

  • I’m receiving messages using a session id “Commands” on a RequireSesssion=true subscription. I am using sessions so that I can make sure that my “command” messages are executed in the appropriate order. In my case some messages will be deferred while a range of other sub-commands do their job.

    Unfortunately I cannot yet reproduce the issue in a simplified code example. But the steps in my code are as follows:

    1. Create a SubscriptionClient and call AcceptMessageSessionAsync() on it
    2. On the received session, start a loop to receive messages with session. ReceiveAsync()
      1. Handle the first message
        1. Write some data to session state using session. SetStateAsync()
        2. Process a file
        3. Send messages with the same SessionId to the topic for next steps to take using SendAsync()
      2. Receive the first message generated in the previous step
        1. Send a new message to the same topic using SendAsync(). But this message  intended for another subscription (with the SessionId field of the BrokeredMessage left at null)
        2. Complete the message using CompleteAsync()

    The SessionLockLostException is thrown at step 2.2.2.

    Some experimentation showed that the exception is only thrown if I also execute step 2.2.1.

    If I replace step 2.2.1 with just a Task.Delay(), then the message completes successfully.

    I wonder if I am trying to do something with sessions that is not supported. I haven’t yet found good documentation on brokered message sessions features yet.

    This is the exception:

    Microsoft.ServiceBus.Messaging.SessionLockLostException was caught
      _HResult=-2146233088
      _message=Channel:uuid:04a0e531-3b8e-4b49-96ab-63288d9a39f7;id=2759;Link:7.TrackingId:ec3b5ee4-cfd9-462f-b2c2-cd32bb6c3656_G29_G29_B5,TimeStamp:2/11/2014 8:12:17 AM
      HResult=-2146233088
      IsTransient=false
      Message=Channel:uuid:04a0e531-3b8e-4b49-96ab-63288d9a39f7;id=2759;Link:7.TrackingId:ec3b5ee4-cfd9-462f-b2c2-cd32bb6c3656_G29_G29_B5,TimeStamp:2/11/2014 8:12:17 AM
      Source=Microsoft.ServiceBus
      StackTrace:
           at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
           at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.RunSynchronously()
           at Microsoft.ServiceBus.Messaging.MessageReceiver.OnComplete(TrackingContext trackingContext, IEnumerable`1 lockTokens, TimeSpan timeout)
           at Microsoft.ServiceBus.Messaging.MessageReceiver.Complete(TrackingContext trackingContext, IEnumerable`1 lockTokens, TimeSpan timeout)
           at Microsoft.ServiceBus.Messaging.MessageReceiver.Complete(IEnumerable`1 lockTokens, TimeSpan timeout)
           at Microsoft.ServiceBus.Messaging.ReceiveContext.Complete()
           at Microsoft.ServiceBus.Messaging.ReceiveContext.Complete()
           at Microsoft.ServiceBus.Messaging.BrokeredMessage.Complete()
           at FS.ServiceBus.Handlers.BaseBrokeredSessionHandler.<handlemessageinnerasync>d__6.MoveNext() in d:\Src\til-tfs-01\Src\ServiceBus\Handlers\BaseBrokeredSessionHandler.cs:line 105
      InnerException: System.ServiceModel.FaultException<system.servicemodel.exceptiondetail>
           _HResult=-2146233087
           _message=Channel:uuid:04a0e531-3b8e-4b49-96ab-63288d9a39f7;id=2759;Link:7.TrackingId:ec3b5ee4-cfd9-462f-b2c2-cd32bb6c3656_G29_G29_B5,TimeStamp:2/11/2014 8:12:17 AM
           HResult=-2146233087
           IsTransient=false
           Message=Channel:uuid:04a0e531-3b8e-4b49-96ab-63288d9a39f7;id=2759;Link:7.TrackingId:ec3b5ee4-cfd9-462f-b2c2-cd32bb6c3656_G29_G29_B5,TimeStamp:2/11/2014 8:12:17 AM
           RemoteStackTrace=
    Server stack trace: 
       at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.ThrowIfFaultMessage(Message wcfMessage)
       at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.HandleMessageReceived(IAsyncResult result)
    
    Exception rethrown at [0]: 
       at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.DuplexCorrelationAsyncResult.End(IAsyncResult result)
       at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.EndRequest(IAsyncResult result)
       at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<getasyncsteps>b__4(RequestAsyncResult thisPtr, IAsyncResult r)
       at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
    
    Exception rethrown at [1]: 
       at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
       at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(IAsyncResult result)
       at Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory`1.RedirectContainerSessionChannel.RequestAsyncResult.<>c__DisplayClass17.<getasyncsteps>b__a(RequestAsyncResult thisPtr, IAsyncResult r)
       at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
    
    Exception rethrown at [2]: 
       at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
       at Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory`1.RedirectContainerSessionChannel.EndRequest(IAsyncResult result)
       at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<getasyncsteps>b__4(RequestAsyncResult thisPtr, IAsyncResult r)
       at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
    
    Exception rethrown at [3]: 
       at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
       at Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
       at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(IAsyncResult result)
       at Microsoft.ServiceBus.Messaging.Sbmp.SbmpTransactionalAsyncResult`1.<getasyncsteps>b__36(TIteratorAsyncResult thisPtr, IAsyncResult a)
       at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
    
    Exception rethrown at [4]: 
    
           Source=Microsoft.ServiceBus
           Action=http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher/fault
           StackTrace:
             Server stack trace: 
                at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.ThrowIfFaultMessage(Message wcfMessage)
                at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.HandleMessageReceived(IAsyncResult result)
             Exception rethrown at [0]: 
                at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
                at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.DuplexCorrelationAsyncResult.End(IAsyncResult result)
                at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.EndRequest(IAsyncResult result)
                at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<getasyncsteps>b__4(RequestAsyncResult thisPtr, IAsyncResult r)
                at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
             Exception rethrown at [1]: 
                at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
                at Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
                at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(IAsyncResult result)
                at Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory`1.RedirectContainerSessionChannel.RequestAsyncResult.<>c__DisplayClass17.<getasyncsteps>b__a(RequestAsyncResult thisPtr, IAsyncResult r)
                at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
             Exception rethrown at [2]: 
                at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
                at Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
                at Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory`1.RedirectContainerSessionChannel.EndRequest(IAsyncResult result)
                at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<getasyncsteps>b__4(RequestAsyncResult thisPtr, IAsyncResult r)
                at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
             Exception rethrown at [3]: 
                at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
                at Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
                at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(IAsyncResult result)
                at Microsoft.ServiceBus.Messaging.Sbmp.SbmpTransactionalAsyncResult`1.<getasyncsteps>b__36(TIteratorAsyncResult thisPtr, IAsyncResult a)
                at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
             Exception rethrown at [4]: 
                at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
                at Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
                at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageReceiver.EndUpdateCommand(IAsyncResult result)
           InnerException:
    </getasyncsteps></getasyncsteps></getasyncsteps></getasyncsteps></getasyncsteps></getasyncsteps></getasyncsteps></getasyncsteps></system.servicemodel.exceptiondetail></handlemessageinnerasync>
    Tuesday, February 11, 2014 9:24 AM

All replies

  • Hi,

    Seems this issue more related with Windows Azure Service Bus, I will move this thread to Windows Azure Service Bus forum for a better help.

    Thanks for your understanding!

    Best Regards


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 12, 2014 5:55 AM
  • Hi traveldev,

    the session lock expires if there is no activity (e.g., receive, complete, abandon, defer) on the session for 60 seconds. If you don't have any activity, you can manually renew the session lock by calling MessageSession.RenewLock() to reset the timer.

    A session lock could be expired in the program flow that you describe if the file processing (step 2.1.2) takes more than a minute. In this case the send call (step 2.2.1) would succeed (because it is not related to the session) and the complete call (step 2.2.2) would fail.

    It is not clear why replacing Send() with Delay() would make this work unless the time to process a file is shorter.

    If you name your namespace or the region your namespace resides in, we can dig through our traces and see if we can find something.

    Thanks, Ruppert

    • Proposed as answer by Daniel.Lindblom Tuesday, February 25, 2020 10:43 AM
    Tuesday, February 18, 2014 6:50 PM
  • Hi Ruppert,

    I think that the SessionLockLostException is not caused by 60 seconds of inactivity because:

    • Step 2.1 takes less than 10 seconds
    • I have experimented with a step 2.1.4 “Call: MessageSession.RenewLock()”. This had no effect.

    My namespace is in the “West Europe” location created under the “NetMatchDev” subscription.

    I have been experimenting with both Service bus on Azure and Service bus 1.1 for Windows Server. My problem occurred in both environments.

    There is a small chance that the error file I provided, was created when pointing my application to Service Bus for windows server. If you cannot match the TrackingIds from the error message in the Azure logs, then please let me know. I will provide another version.

    Thanks,

    Jef

    • Proposed as answer by Daniel.Lindblom Tuesday, February 25, 2020 10:43 AM
    • Unproposed as answer by Daniel.Lindblom Tuesday, February 25, 2020 10:43 AM
    Friday, February 21, 2014 2:18 PM
  • Hi Jef,

    We looked at the tracking ID but weren't able to pinpoint any issue. Can you supply us with the name of your namespace and entity and additional tracking IDs in case you have some?

    Thanks, Ruppert

    Friday, February 28, 2014 10:00 PM
  • the session lock expires if there is no activity (e.g., receive, complete, abandon, defer) on the session for 60 seconds. If you don't have any activity, you can manually renew the session lock by calling MessageSession.RenewLock() to reset the timer.


     Hi Ruppert! I am curious, where did you read this information? I have missed it and was wondering why i got SessionLockLostException before the expiry of the lock. Really found your answer helpful.

    Best regards Daniel
    Tuesday, February 25, 2020 10:34 AM