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

NATS.net JetStream singleton issues #620

Open
Bykiev opened this issue Aug 29, 2024 · 6 comments
Open

NATS.net JetStream singleton issues #620

Bykiev opened this issue Aug 29, 2024 · 6 comments

Comments

@Bykiev
Copy link
Contributor

Bykiev commented Aug 29, 2024

Observed behavior

When creating a singleton connection to NATS JetStream the error is thrown:

NATS.Client.JetStream.NatsJSApiNoResponseException: No API response received from the server
at NATS.Client.JetStream.NatsJSContext.JSRequestAsync[TRequest,TResponse](String subject, TRequest request, CancellationToken cancellationToken)
at NATS.Client.JetStream.NatsJSContext.JSRequestAsync[TRequest,TResponse](String subject, TRequest request, CancellationToken cancellationToken)
at NATS.Client.JetStream.NatsJSContext.JSRequestResponseAsync[TRequest,TResponse](String subject, TRequest request, CancellationToken cancellationToken)
at NATS.Client.JetStream.NatsJSContext.GetStreamAsync(String stream, StreamInfoRequest request, CancellationToken cancellationToken)
at NATS.Client.KeyValueStore.NatsKVContext.GetStoreAsync(String bucket, CancellationToken cancellationToken)

My config:

builder.Services.AddNats(1, opts =>
{
    return new NATS.Client.Core.NatsOpts()
    {
        Name = name,
        Url = url,
        SerializerRegistry = NatsJsonSerializerRegistry.Default
    };
});

We've tried to use a connection pool with 1000 connection and everything is working as expected. Maybe it's not possible to subscribe and update the same store using one connection? I didn't find any information about it in the docs. And if it's not possible, how many connections should be in a connection pool?

Expected behavior

No exception is thrown when NATS is registered as singleton

Server and client version

NATS server 2.10.18
NATS .NET v2.3.3

Host environment

Docker image

Steps to reproduce

No response

@mtmk
Copy link
Collaborator

mtmk commented Aug 29, 2024

we see this error sometimes. I'm assuming it happens intermittently and you have other consumers on the same connection. it may be head of line blocking. my guess is you can use keyed services and use a seperate connection for your consumers which may flood the connection.

edit: we also had reports of network issues e.g. using public IP of your cloud VM which might have DDoS protection

@Bykiev
Copy link
Contributor Author

Bykiev commented Aug 29, 2024

Yes, we have a multiple consumers. We did some tests and I can see this error even with 10 connections in a pool. We've updated the NATS server docker image to v2.10.19, seems the problem still exists. What can we do to use NATS JS with multiple consumers?

@Bykiev
Copy link
Contributor Author

Bykiev commented Aug 29, 2024

After some time we didn't get any data via JS on some of the consumers, it seems the connection is dropped by someone or smth else is happened.

@Bykiev
Copy link
Contributor Author

Bykiev commented Aug 29, 2024

I did some research and this seems to be DI or pooler issue. I've removed the DI part from the project and created a single connection for watcher and another one for writing. This is working without any issues.

@mtmk
Copy link
Collaborator

mtmk commented Aug 29, 2024

I did some research and this seems to be DI or pooler issue. I've removed the DI part from the project and created a single connection for watcher and another one for writing. This is working without any issues.

this is interesting. pooler is just a simple round robin of connections. are you on slack.nats.io maybe we can have a chat there.

edit: you should also be able to used keyed DI in you're using net8

@Bykiev
Copy link
Contributor Author

Bykiev commented Aug 29, 2024

are you on slack.nats.io maybe we can have a chat there

Unfortunately, It's not available in my country. I've created another issue #621, can be related to this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants