title: What controls when the MessageSession lock expires, if the client can't call Close?
body: <p><strong>Context</strong>: MSDN documentation on Service Bus queues and message sessions says "When the MessageSession object is accepted and while it is held by a client, that client holds an exclusive lock on all messages with that session's SessionId that exist in the queue or subscription, and also on all messages with that SessionId that still arrive while the session is held.</p>
  
  <p>The lock is released when Close or CloseAsync are called, <em>or when the lock expires in cases in which the application is unable to perform the close operation</em>"</p>
  
  <p><strong>My Interpretation</strong>: I'm interpreting the above to mean that a MessageSession has a lock on a queue session, which is why other clients can't call AcceptMessageSessionAsync with the same SessionID - they'd get a SessionCannotBeLockedException.</p>
  
  <p><strong>Question</strong>: Assuming my interpretation is accurate, what controls <em>when</em> the MessageSession lock expires in cases where an application can't perform the Close operation? I know LockDuration on the queue <em>doesn't</em> accomplish this because I tried it. </p>
  
  <p><strong>Sample Code</strong>:</p>
  
  <pre><code>var sessionClient = new SessionClient(ServiceBusConnectionString, QueueName, ReceiveMode.PeekLock);
  var session = await sessionClient.AcceptMessageSessionAsync("0");
  // ReceiveAsync seems to wait for 60 seconds, 
  // even if the LockDuration on the queue is 30 seconds. 
  var message = await session.ReceiveAsync();
  // Once ReceiveAsync returns, I'd expect to receive a SessionLockLost
  // exception at some point since the lock should expire, according to MSDN
  Console.ReadKey();
  </code></pre>