Closed JoeCqupt closed 2 months ago
The changes enhance the error handling and readability of the decode
method in the ProtocolCodeBasedDecoder
class. Key improvements include restructuring the try-finally block for better buffer index management and adding explicit checks for null protocol objects. The test suite for the decoder is also strengthened with new tests that confirm proper behavior when illegal packets are processed, ensuring robust performance under error conditions.
Files | Change Summary |
---|---|
src/main/java/com/alipay/remoting/codec/ProtocolCodeBasedDecoder.java src/test/java/com/alipay/remoting/codec/ProtocolCodeBasedDecoderTest.java |
The decoder's decode method is modified for improved error handling and clarity, with added checks for null protocol objects. The test suite is updated with enhanced tests to validate decoder behavior for illegal packets, including checks on ByteBuf state. |
sequenceDiagram
participant Client
participant Decoder
participant ByteBuf
Client->>Decoder: Send data
Decoder->>ByteBuf: Process data
ByteBuf->>Decoder: Check for errors
alt No error
Decoder->>Client: Return decoded data
else Error occurred
ByteBuf->>Decoder: Reset reader index
Decoder->>Client: Throw CodecException
end
🐇 Through the code, we hop and play,
With tweaks that brighten the day!
Errors handled, tests anew,
Our decoder shines, it’s tried and true!
So let’s all cheer, hip-hip-hooray!
For robust code that’s here to stay! 🎉
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
这个CI好像有问题,线下跑的单测一点问题没有,CI跑就报错 线下:
CI: https://github.com/sofastack/sofa-bolt/actions/runs/10111851447/job/27964641532?pr=355#step:5:1442
这个CI好像有问题,线下跑的单测一点问题没有,CI跑就报错 线下: CI: https://github.com/sofastack/sofa-bolt/actions/runs/10111851447/job/27964641532?pr=355#step:5:1442
我跟你有相同的问题
@chuailiwu
Hi, @JoeCqupt , I doubt if it is a bug of bolt. ByteBuf will be released at channelInactive
method. I think you need to check in what condition (such as you encounter an exception when decoding but not close the connection ) you did not invoke this method.
Hi, @JoeCqupt , I doubt if it is a bug of bolt. ByteBuf will be released at
channelInactive
method. I think you need to check in what condition (such as you encounter an exception when decoding but not close the connection ) you did not invoke this method.
yep. you are right. This modification is optional
reproduce code
when
ProtocolCodeBasedDecoder#decode()
throw exception . ByteBuf param not releasedSummary by CodeRabbit
New Features
Bug Fixes