-
Notifications
You must be signed in to change notification settings - Fork 254
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
Remove ByteBuf
auto-release
#264
Comments
👍 |
Thanks @benjchristensen for the 👍 |
@NiteshKant how do you do this in RxNetty? RxNetty read a ByteBuf from netty but there was no subscriber. In this case the ByteBuf is unconsumed and RxNetty will release such a ByteBuf /cc @simonbasle |
Thats a good question. RxNetty hands off
Both the above methods return a |
@NiteshKant I've looked at UnicastContentSubject when you linked it before, interesting expansion on the BufferUntilSubscriber subject ;) |
As @NiteshKant and I discuss this further there are two options:
When
When the handler function is invoked synchronously, then auto-release would work. If the developer chooses to do something async before consuming the |
The changes in 0.5.x do not auto-release the |
Available in 0.5.x branch |
SinkSubscriber has had it's pipeline slightly changed to ensure that when trying to read an error message response body that it is able to do so. The `ByteBuf` from `response.getContent()` has it's ref-counter automatically decremented when the response object leaves the netty thread and results in the content being disposed. When SinkSubscriber would then attempt to read the content to construct the error message it would fail. This change moves to logic of reading and mapping over the content before we move to the compute thread to invoke the callback on the `SinkOperation`. See ReactiveX/RxNetty#264
Today RxNetty tries to alleviate the load of managing
ByteBuf
lifecycle from the user and employs an auto-release strategy, post invokingonNext
on the subscriber listening for data.The above is convenient in normal scenarios however it becomes non-intuitive in scenarios where the processing of
ByteBuf
happens in a separate thread as described in the issue #203A slightly convoluted example of the above is in case of proxies where the request payload from the server is written as a request to the client (calling the origin server) and response from the origin (from
HttpClient
) is written to the server response. In this case, the thread change is subtle which is the eventloop processing the connection between the client and the server.The above issues makes me feel that we should completely eliminate this auto-release behavior and follow a simple principle The eventual consumer of the
ByteBuf
should release theByteBuf
Doesn't it mean that every client has to worry about
ByteBuf
management?Yes, thats true. However, it isn't as bad as it sounds!
Few facts
ByteBuf
is created, it has a ref count of 1. Everytime aByteBuf
is written to netty's channel, netty releases thisByteBuf
. So, if the code is only shuntingByteBuf
from one channel to another (proxy case), there is no special handling required.ByteBuf
after use. So, majority of the code should not be dealing withByteBuf
ByteBuf
, the simple rule will be to unconditionally release it after they are done processing with theByteBuf
. There are no special cases of thinking about in which scenarios (same thread or different) one should release theByteBuf
and which they should not.What about unconsumed
ByteBuf
s?The above scenarios become a bit more complex when we have to deal with unconsumed
ByteBuf
s. There are two distinct scenarios:ByteBuf
from netty but there was no subscriber. In this case theByteBuf
is unconsumed andRxNetty
will release such aByteBuf
ByteBuf
to a subscriber which cached theByteBuf
, which no code consumed. In this case, there should be an explicit dispose functionality available that should discard all unusedByteBuf
. Much as this subject in zuul. In order to make this case easier for user, RxNetty will provide such a subject that can be used by users directly in scenarios where they need to cache.Over all I feel, hiding the fact that netty expects users to do memory management of
ByteBuf
and making it easier for users, fills some gaps but exposes plenty more and adds confusion in the mind of users as to how to correctly use them. OTOH, if we are open about the fact that it is required to manageByteBuf
, it will create a much more intuitive system.The text was updated successfully, but these errors were encountered: