Azure/azure-sdk-for-js

[Service Bus] receiver.receiveMessages() doesn't reject when connection lost

Closed this issue · 5 comments

It's possible for the promise returned by receiver.receiveMessages() to complete without rejecting or resolving. Here is the scenario I encountered:

  1. receiver.receiveMessages() has been called and is polling the service bus.
  2. The connection is lost e.g. due to network problems.
  3. From debug logging you can see that the BatchingReceiver has been closed.
  4. This does not result in the receiveMessages promise rejecting, nor does it resolve after idleTimeoutInSeconds.
  5. The node script terminates as there are no functions still executing

This results in a confusing scenario for error handling:

const client = sbClient.createSubscriptionClient(topicName, subscriptionName)
const receiver = client.createReceiver(ReceiveMode.peekLock)

const pollQueue = async () => {
  try {
    const messages = await receiver.receiveMessages(1, WAIT_TIME)
    // Never reached - doesn't resolve
  } catch (err) {
    // Never reached - doesn't reject
  } finally {
    // Never reached either :-(
  }
}

Thanks for reporting @grahambates

How did you simulate the loss of connection? By disabling wifi/network while the receiveMessages is running or by some other means?

Can you also please share the version of the Service Bus library you are using?

Yes, disabling wifi or pulling out a network cable seems to be the easiest way to reproduce this.
We're using version 1.1.0.

Also seeing this issue. Do we know when this will be pushed out?

We have found the root cause for this problem and are in the process of trying out a few different solutions. #6338 is the draft PR that discusses one such solution.

We will post back here once we have an update.