Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServiceBus doesn't complete the messages from the prefetch buffer #20380

Closed
Tracked by #18819
okyryliuk opened this issue Apr 5, 2021 · 2 comments
Closed
Tracked by #18819

ServiceBus doesn't complete the messages from the prefetch buffer #20380

okyryliuk opened this issue Apr 5, 2021 · 2 comments
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus
Milestone

Comments

@okyryliuk
Copy link

okyryliuk commented Apr 5, 2021

Describe the bug
If the lock expires in the prefetch buffer, the message is treated as abandoned and is again made available for retrieval from the queue. When there is more than a single failed message in the prefetch buffer, the client tries to process those messages again but doesn't complete any message even if they are processed successfully on the second attempt. If there is one failed message in the prefetch buffer, and it may be completed on the second attempt, all messages can be completed successfully.

To Reproduce

  • The message lock duration is set to 10 seconds
  • Prefetch count is set to 5 messages
  • At least 2 messages should be processed more than the lock duration time

Code Snippet

ServiceBusReceiverAsyncClient receiver = new ServiceBusClientBuilder()
        .connectionString(CONNECTION_STRING)
        .receiver()
        .disableAutoComplete()
        .prefetchCount(5)
        .topicName(TOPIC)
        .subscriptionName(SUBSCRIPTION)
        .buildAsyncClient();

    AtomicInteger index = new AtomicInteger();
    receiver.receiveMessages()
        .flatMap(message -> {
          System.out.printf("Sequence #: %s. Contents: %s%n", message.getSequenceNumber(), message.getBody());
          try {
            int sleepTime = index.get() % 2 == 0 ? 12000 : 0;
            Thread.sleep(sleepTime);
            index.getAndIncrement();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
          return receiver
              .complete(message)
              .onErrorResume(e -> {
                e.printStackTrace();
                return Mono.empty();
              });
        })
        .doOnError(e -> System.out.println("ERROR: " + e.getMessage()))
        .doOnComplete(() -> System.out.println("DONE"))
        .subscribe();

Expected behavior
All messages from the prefetch buffer should be completed successfully after the successful attempt.

Setup (please complete the following information):

  • OS: Windows
  • IDE : IntelliJ
  • Version of the Library used: 7.1.0
@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Apr 5, 2021
@joshfree joshfree added Client This issue points to a problem in the data-plane of the library. Service Bus labels Apr 8, 2021
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Apr 8, 2021
@joshfree joshfree added this to the [2021] May milestone Apr 8, 2021
@joshfree
Copy link
Member

joshfree commented Apr 8, 2021

@YijunXieMS could you please take a look?

/cc @hemanttanwar

@anuchandy
Copy link
Member

Please refer to this git-ticket #26632 where the crew evaluated this. The decision is not to do anything on the client-side to handle such expired messages.

Also refer this section on general guideline https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-prefetch?tabs=dotnet#why-is-prefetch-not-the-default-option

The maximum prefetch count and the lock duration configured on the queue or subscription need to be balanced such that the lock timeout at least exceeds the cumulative expected message processing time for the maximum size of the prefetch buffer, plus one message. At the same time, the lock timeout shouldn't be so long that messages can exceed their maximum time to live when they're accidentally dropped, and so requiring their lock to expire before being redelivered.

Closing this ticket based on the above data.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus
Projects
None yet
Development

No branches or pull requests

6 participants