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

Not thread safe to start subscriptions concurrently in a connection #917

Open
MENNAELMESALMY opened this issue Aug 5, 2024 · 0 comments
Labels
defect Suspected defect such as a bug or regression

Comments

@MENNAELMESALMY
Copy link

Observed behavior

we saw this error getting thrown when trying to start multiple subscriptions concurrently

"   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at NATS.Client.Connection.AddSubscription(Subscription s)
   at NATS.Client.Connection.subscribeAsync(String subject, String queue, EventHandler`1 handler, CreateAsyncSubscriptionDelegate createAsyncSubscriptionDelegate)
   at NATS.Client.JetStream.JetStream.CreateSubscription(String userSubscribeSubject, PushSubscribeOptions pushSubscribeOptions, PullSubscribeOptions pullSubscribeOptions, String queueName, EventHandler`1 userHandler, Boolean autoAck, PullMessageManager pmmInstance)
   at NATS.Client.JetStream.JetStream.PushSubscribeAsync(String subject, EventHandler`1 handler, Boolean autoAck, PushSubscribeOptions options)
   at NATS.Client.KeyValue.KeyValueWatchSubscription..ctor(KeyValue kv, IList`1 keyPatterns, IKeyValueWatcher watcher, UInt64 fromRevision, KeyValueWatchOption[] watchOptions)
   at NATS.Client.KeyValue.KeyValue.WatchAll(IKeyValueWatcher watcher, KeyValueWatchOption[] watchOptions)

...

I saw that the connection keeps track of all subscriptions in a dictionary but it's not thread safe

Expected behavior

Starting multiple subscriptions is thread-safe.

Server and client version

c# version: 1.1.5

Host environment

No response

Steps to reproduce

No response

@MENNAELMESALMY MENNAELMESALMY added the defect Suspected defect such as a bug or regression label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Suspected defect such as a bug or regression
Projects
None yet
Development

No branches or pull requests

1 participant