smbecker opened a new issue, #266:
URL: https://github.com/apache/pulsar-dotpulsar/issues/266

   ### Description
   
   This is an odd issue and I'm not entirely sure if this is a client-side 
issue in DotPulsar or an issue in the pulsar broker. However, if you leverage a 
`CancellationToken` that eventually gets cancelled when calling `Receive` and 
do this repeatedly, each call will cause the `availablePermits` to increase on 
the topic stats for the broker. 
   
   ### Reproduction Steps
   
   The following can reproduce the issue with the latest (4.2.3) client and 
server (4.0.3):
   
   ```c#
   using System.Text.Json;
   using DotPulsar;
   using DotPulsar.Extensions;
   
   const string topic = "public/default/sample";
   const string subscription = "sample";
   const string serviceUri = "pulsar://localhost:6650";
   const string adminUri = "http://localhost:8080";;
   
   await using var pulsarClient = PulsarClient.Builder()
        .ServiceUrl(new Uri(serviceUri))
        .Build();
   
   await using var producer = pulsarClient.NewProducer()
        .Topic($"persistent://{topic}")
        .Create();
   
   await using var consumer = pulsarClient.NewConsumer()
        .Topic($"persistent://{topic}")
        .SubscriptionType(SubscriptionType.Shared)
        .ConsumerName(Guid.NewGuid().ToString())
        .SubscriptionName("sample")
        .MessagePrefetchCount(1)
        .Create();
   
   await producer.Send(new byte[1]);
   
   for (int i = 0, count = 20; i < count; i++) {
        consumer.TryReceive(out _);
        Console.WriteLine("Permits: {0}", await GetPermits());
        await Task.Delay(500);
   }
   
   
   static async ValueTask<long> GetPermits() {
        using var client = new HttpClient();
        using var response = await 
client.GetAsync($"{adminUri}/admin/v2/persistent/{topic}/stats");
        if (response.IsSuccessStatusCode) {
                await using var stream = await 
response.Content.ReadAsStreamAsync();
                var json = await JsonDocument.ParseAsync(stream);
                if (!json.RootElement.TryGetProperty("subscriptions", out var 
subscriptionsProperty)) {
                        return 0;
                }
   
                if (!subscriptionsProperty.TryGetProperty(subscription, out var 
subscriptionProperty)) {
                        return 0;
                }
   
                if (subscriptionProperty.TryGetProperty("consumers", out var 
consumersProperty)) {
                        foreach (var consumer in 
consumersProperty.EnumerateArray()) {
                                if (consumer.TryGetProperty("availablePermits", 
out var permitsProperty)) {
                                        var permits = 
permitsProperty.GetInt64();
                                        if (permits > 0) {
                                                return permits;
                                        }
                                }
                        }
                }
        }
   
        return 0;
   }
   ```
   
   ### Expected behavior
   
   Given the 
[documentation](https://pulsar.apache.org/docs/next/administration-stats/#consumer-stats:~:text=to%20the%20consumer.-,availablePermits,-The%20number%20of)
 on what `availablePermits` means, this behavior does not seem correct. I would 
not expect `availablePermits` to continue to increase like it does.
   
   ### Actual behavior
   
   Each successive call will increment `availablePermits`
   
   ### Regression?
   
   _No response_
   
   ### Known Workarounds
   
   _No response_
   
   ### Configuration
   
   * Which version of .NET is the code running on? net8.0
   * Which version of DotPulsar are you using? 4.2.3
   * What OS and version, and what distro if applicable? Ubuntu 24.04
   * What is the architecture (x64, x86, ARM, ARM64)? x86
   * Do you know whether it is specific to that configuration? This does not 
appear to be configuration specific
   * If you're using Blazor, which web browser(s) do you see this issue in? NA
   
   ### Other information
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to