Fixed race in UnicastContentSubject and discard of connection #310
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Race conditions in UnicastContentSubject.
UnicastContentSubject has a potential to loose terminal events sent to the subject due to a race condition.
The race condition was when a terminal event arrives between draining all buffered notifications and atomically replacing the observer. Since, the observer, was draining all such buffered notifications, on recieving a notifications, the terminal notifications mentioned above were lost.
This subject was copied from RxJava BufferTillSubscriber which had fixed this race. The intention of not using that subject in RxJava was that it was an internal class. The tax of such bugs is high as compared to rxjava changing the subject contract, hence, using rxjava's subject now.
Mark connection as disposed before close.
On unsubscribe, without getting a response, the discard connection flag was not set before close() was called.
This lead to the connection which is supposed to be discarded, return to the pool and potentially used by another request.
This will cause a request to immediately fail since the connection will be closed (as a result of conn. release event) before the request is written.
Now, marking the connection as disposed, when the unsubscribe happens before completion of response.