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

Consumer Fetch isn't throwing exception when 409 Exceeded MaxRequestBatch message received #236

Closed
mtmk opened this issue Nov 25, 2023 · 1 comment · Fixed by #265
Closed
Labels
bug Something isn't working

Comments

@mtmk
Copy link
Collaborator

mtmk commented Nov 25, 2023

Observed behavior

// Install NuGet packages `NATS.Net` and `Microsoft.Extensions.Logging.Console`.
using Microsoft.Extensions.Logging;
using NATS.Client.Core;
using NATS.Client.JetStream;
using NATS.Client.JetStream.Models;

using var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole());
await using var nats = new NatsConnection(new NatsOpts { LoggerFactory = loggerFactory });
var js = new NatsJSContext(nats);

var stream = await js.CreateStreamAsync(new StreamConfig("EVENTS", new[] { "events.>" }));

var consumer = await stream.CreateConsumerAsync(new ConsumerConfig("processor") { MaxBatch = 2 });

await foreach (var msg in consumer.FetchAsync<string>(opts: new NatsJSFetchOpts
               {
	               MaxMsgs = 10,
	               NotificationHandler = (notification, token) =>
	               {
		               Console.WriteLine($">>>> {notification.Name}");
		               return Task.CompletedTask;
	               }
               }))
{
}

Output:

info: NATS.Client.Core.NatsConnection[1001]
      Try to connect NATS nats://localhost:4222
info: NATS.Client.Core.Internal.NatsReadProtocolProcessor[1005]
      Received server info: ServerInfo { Id = NCPYXNOZUU7QDMTVSD6CCLIHR7V2NZN27KIIRACGBPAK6K5EUI5LX46X, Name = NCPYXNOZUU7QDMTVSD6CCLIHR7V2NZN27KIIRACGBPAK6K5EUI5LX46X, Version = 2.10.5, ProtocolVersion = 1, GitCommit = 0883d32, GoVersion = go1.21.4, Host = 0.0.0.0, Port = 4222, HeadersSupported = True, AuthRequired = False, TlsRequired = False, TlsVerify = False, TlsAvailable = False, MaxPayload = 1048576, JetStreamAvailable = True, ClientId = 11, ClientIp = ::1, Nonce = , Cluster = , ClusterDynamic = False, ClientConnectUrls = , WebSocketConnectUrls = , LameDuckMode = False }
info: NATS.Client.Core.NatsConnection[1001]
      Connect succeed NATS .Net Client, NATS nats://localhost:4222
warn: NATS.Client.JetStream.Internal.NatsJSFetch[2005]
      Unhandled protocol message: 409 Exceeded MaxRequestBatch of 2
>>>> Timeout
info: NATS.Client.Core.NatsConnection[1001]
      Disposing connection NATS .Net Client

Expected behavior

consumer.FetchAsync() to throw exception and maybe a notification.

Server and client version

client: 2.0.0
server: 2.10.5

@mtmk mtmk added the bug Something isn't working label Nov 25, 2023
@mtmk
Copy link
Collaborator Author

mtmk commented Nov 25, 2023

Also other codes to consider:

  • 409 Exceeded MaxRequestExpires of 1s
  • 409 Exceeded MaxWaiting
  • 409 Exceeded MaxRequestMaxBytes of 3
  • 409 Exceeded MaxRequestBatch of 2

Maybe all 409s?

edit: not all 409s are terminal e.g. 409 Server Shutdown

Any thing starts with Exceeded Max:

➜  nats-server git:(release/v2.10.5) grep -e 'sendErr.*Exceeded Max' server/consumer.go
                sendErr(409, fmt.Sprintf("Exceeded MaxRequestBatch of %d", o.cfg.MaxRequestBatch))
                sendErr(409, fmt.Sprintf("Exceeded MaxRequestExpires of %v", o.cfg.MaxRequestExpires))
                sendErr(409, fmt.Sprintf("Exceeded MaxRequestMaxBytes of %v", o.cfg.MaxRequestMaxBytes))
                sendErr(409, "Exceeded MaxWaiting")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant