azure-sdk-for-js: Message receiver does not resolve neither reject after internet connection loss
- Package Name: @azure/service-bus
- Package Version: 1.1.3
- Operating system: Ubuntu 18
- nodejs
- version: v12.16.1
- typescript
- version:
- browser
- name/version:
- Is the bug related to documentation in
- README.md
- source code documentation
- SDK API docs on https://docs.microsoft.com
Describe the bug
We noticed messages accumulating in our servicebus queue and figured out that the problem was related to our back-end. We discovered this:
The method receiver.receiveMessages
is locking undefenitelly when the internet connection is out for a couple of minutes (10 minutes is one way to reproduce it).
If the offline period is short (couple of seconds) the method receiver.receiveMessages
call recovers and starts consuming messages again. We observed the problem only with a couple of minutes without internet. Once that couple of minutes pass, the method receiver.receiveMessages
will not resolve anymore and will not consume any more messages, requiring the restart of the application.
The client is also not logging any error or exception. It simply stays blocked at const messages = await this.receiver.receiveMessages(10);
.
// We use this to keep consuming messages
async handle() {
while (true) {
try {
await this.handleMessages();
} catch (e) {
Logger.error(e);
}
}
}
// This is the actual code
async handleMessages() {
try {
const { connection, queueName } = this.properties;
this.sbClient = ServiceBusClient.createFromConnectionString(connection);
this.queueClient = this.sbClient.createQueueClient(queueName);
this.receiver = this.queueClient.createReceiver(ReceiveMode.receiveAndDelete);
const messages = await this.receiver.receiveMessages(10);
messages.forEach(({ body }) => this.service.execute(body.data));
await this.queueClient.close();
} finally {
await this.sbClient.close();
}
}
To Reproduce Steps to reproduce the behavior:
- Start the code to receive messages
- Turn-off internet connection
- Enqueue a message in the queue
- Await 10 minutes
- Turn-on internet connection
Messages will not be received from the queue, and the program will need to be restarted to receive messages again.
This problem won’t happen if the internet offline period is very short (couple of seconds).
Expected behavior The receiving of messages should resolve automatically, or the process should throw an exception indicating that the consumption has failed and cannot be resolved.
Screenshots If applicable, add screenshots to help explain your problem.
Additional context Add any other context about the problem here.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 17 (17 by maintainers)
@evandropomatti Thanks for reporting this issue. I noticed that your handleMessages sample doesn’t have a catch block. Would it be possible to add a catch to your try and log any errors you hit?
The other thing is you may need to close your sbClient in the finally block after closing your queue client. When I ran your modified sample locally I was able to catch errors from the receive call. If you can verify if an error is being thrown that might give us some clues.
If an error is being thrown by your receive call, then the service bus client doesn’t get closed (just the queue client does since it is in the finally block). I notice this is running in a loop, so it might be possible that there’s an issue with too many open service bus connections.