Closed cbenien closed 7 years ago
@cbenien thank you for this report and the patch
OnNext simultaneously from multiple threads is a bad idea
This definitely looks like a bug. I will try to find time this week to take a better look and will do something about it.
reviewed the fix by @cbenien and it looks reasonable. As no one here has the bandwidth to think on any other "more preferred" way to do it, I made the decision to merge the pull request and publish v2.0.1 along with a couple other issues.
Hi,
I've been debugging a problem for the last week where my consuming application would crash with an out-of-memory exception. What I observed:
I think I figured out the root cause of the problem. In the Consumer class, there is a BehaviorSubject
which is controlling the flow control. I think what goes wrong is that this subject is written to simultaneously from multiple threads. Once from the thread that increments the counter for new messages:
And once from the thread that acknowledges the messages (called from my application)
I'm not an expert on threading and concurrency with reactive extensions, but calling OnNext simultaneously from multiple threads is a bad idea, e.g. discussed here: http://stackoverflow.com/questions/14396449/why-are-subjects-not-recommended-in-net-reactive-extensions
I could fix this pretty quickly by putting a
lock
statement around both calls to OnNext. But I'm not sure if that is the best possible solution to the problem. If anyone's interested, I can put together a pull request for this.Or am I doing something wrong in my application? Am I expected to call
Ack
on the original thread? Would that solve it?