You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1 when using ByteBufPayload #893
Provided code throws IllegalReferenceCountException when I use ByteBufPayload and publish result on different thread.
There is no exception when I use DefaultPayload.create("World".getBytes()) insted of ByteBufPayload.
The first problem here is that DefaultPayload and ByteBufPayload has different refcount management. The DefayltPayload is an unpooled payload, so calling the release method makes no effect on it. In contrast, calling the ByteBufPayload#release method releases all resources used by this Payload.
It means that if there are data and metadata, these content will not be available anymore after calling the release on the ByteBufPayload.
That said, if you sliced data and then called release, the slice will be released as well and the content of the slice will not be accessible anymore.
var dataBuf = payload.sliceData();
payload.release(); // after this dataBuf is freed as well
return dataBuf.toString(StandardCharsets.UTF_8); // here you observe error
To fix that you may defer the release to the point when content is read. For example:
var dataBuf = payload.sliceData();
var content = dataBuf.toString(StandardCharsets.UTF_8);
payload.release();
return content;
The above should fix the problem.
Let me know if you experience something different than that,
Thank you for your attention.
I have tried your suggestion but unfortunately id doesn't work, there is still the same exception.
I want you to notice the line
.publishOn(Schedulers.parallel())//TODO if remove this line code works as expected
Activity
OlegDokuka commentedon Jul 23, 2020
Hi @rasentry!
Thanks for asking that!
The first problem here is that
DefaultPayloadandByteBufPayloadhas different refcount management. TheDefayltPayloadis an unpooled payload, so calling thereleasemethod makes no effect on it. In contrast, calling theByteBufPayload#releasemethod releases all resources used by thisPayload.It means that if there are data and metadata, these content will not be available anymore after calling the
releaseon theByteBufPayload.That said, if you sliced data and then called release, the slice will be released as well and the content of the slice will not be accessible anymore.
To fix that you may defer the release to the point when content is read. For example:
The above should fix the problem.
Let me know if you experience something different than that,
Cheers,
Oleh
rasentry commentedon Jul 23, 2020
Thank you for your attention.
I have tried your suggestion but unfortunately id doesn't work, there is still the same exception.
I want you to notice the line
if I remove that line error disappear
OlegDokuka commentedon Jul 23, 2020
Indeed. This is a bug. Thank you for finding that! Appreciate this!
OlegDokuka commentedon Jul 27, 2020
fixed in #894 should be available started from 1.0.2