-
Notifications
You must be signed in to change notification settings - Fork 41
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
Invalid behavior when using same NATS connection for both NATS and STAN subscriptions #184
Comments
Reusing the same connection is supported - we may have a bug here. I'm not sure why you'd be getting a timeout exception upon establishing a subscription. It is concerning that you have a "partial" subscription, meaning the client didn't clean up. Which version of the client are you using, and would you be able to reproduce this in a simple app you could share? |
Sure, I will try to reproduce it and post here link to the repo. I'm using the latest version of both NATS and STAN clients. |
@dorny, We'd appreciate it, it'd really help us out. If you have a full stack trace from the BTW, I found an issue where the subscription timeout is hardcoded to 2s. That needs to be made configurable. I'll create an issue for that. |
Minimal example: https://gist.github.com/dorny/6255e9a6679a2f582c98e3fa93b91df0 My initial assumption that it's caused by some threading issue was wrong. Output of the code in gist:
|
Unfortunately your test code (ported to tests) doesn't seem reproduce the error, I'll revisit that to be sure. Here are my thoughts... STAN subscriptions are created by:
I suspect the problem lies in a timeout on request in step 3, where the NATS streaming server receives the message and starts forwards data, but the response is lost before the client times out. I'll continue to look at this. Regardless, I'll suggest increasing the timeouts - which is impossible at the moment - so I'll add #185 then we can test to see if a longer timeout resolves the issue for you. When this happens does the call to |
I'm pretty sure this is not an performance issue so increasing timeout won't help here. I tried my test code again and the bug is always reproduced.
There must be some bug on at least one side of the connection - this client or NATS Streaming server itself. |
I'll keep looking... thanks @dorny. |
FYI, outside of xunit I was able to reproduce this with .NET core 3.1. When stepping through things work fine, so likely a timing/threading issue. I noticed .NET core framework itself crash a few times as well, not good. Wow, you've found a good one... :) I'll let you know what I find. |
Interesting find - if get the task and wait... success. //await nc.RequestAsync("rpc.test", dummyMessage);
var t = nc.RequestAsync("rpc.test", dummyMessage);
t.Wait(); And this fails... var t = nc.RequestAsync("rpc.test", dummyMessage);
await t; |
I believe I've found the issue. It's a problem that's been resolved in the core NATS library. See: nats-io/nats.net#404. Building with current source and upgrading the core NATS client to 0.11.0-pre2 cleared this up. Because the new release of the core NATS client will require net 4.6 compatibility, I'll need to coordinate releases for both NATS.Client and STAN.Client releases. I'm planning on getting a release out of the core NATS client soon (hopefully this week). Then I'll get a pre-release of this client so you can verify. |
I had encountered quite invalid behavior:
We have single instance of NATS
IConnection
. We use it to setup NATS subscriptions and the same instance is also used inIStanConnection
(passed viaStanOptions.NatsConn
).While setting up STAN subscriptions via
IStanSubscription.Subscribe(subject, options, handler)
theNATSTimeoutException
is thrown. However ourhandler
is still being executed, processing the incoming messages. However as the exception is thrown from theSubscribe(...)
method, there is no instance ofIStanSubscription
we could dispose.We are encountering this behavior almost all the time during application startup, when most of the subscriptions are configured. However if we add new STAN subscription later, it works as expected.
I tried various things - using locks to serialize access to connection, tested it with or without actual data stored in NATS Streaming (we use FILE store). Nothing helped.
Finally I get rid of this behavior once I stopped passing existing
IConnection
to STAN and let it create it's own connection.Is reusing of same connection for both NATS and STAN supported? To my understanding, STAN is using NATS just as a transport layer and it should work just fine. If it's not the case, better mention that in a docs
Assuming it should be supported, then:
Subscribe(...)
method, it shouldn't actually establish the subscription and invoke the provided handlerThe text was updated successfully, but these errors were encountered: