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:
- Create a SubscriptionClient and call AcceptMessageSessionAsync() on it
- On the received session, start a loop to receive messages with session. ReceiveAsync()
- Handle the first message
- Write some data to session state using session. SetStateAsync()
- Process a file
- Send messages with the same SessionId to the topic for next steps to take using SendAsync()
- Receive the first message generated in the previous step
- 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)
- Complete the message using CompleteAsync()
- Handle the first message
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>