szetszwo commented on a change in pull request #278:
URL: https://github.com/apache/incubator-ratis/pull/278#discussion_r523706250
##########
File path:
ratis-netty/src/main/java/org/apache/ratis/netty/server/NettyServerStreamRpc.java
##########
@@ -151,11 +152,23 @@ public void addRaftPeers(Collection<RaftPeer> newPeers) {
private ChannelInboundHandler newChannelInboundHandlerAdapter(){
return new ChannelInboundHandlerAdapter(){
+ private final AtomicReference<DataStreamRequestByteBuf> currentRef = new
AtomicReference<>();
+
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
- if (msg instanceof DataStreamRequestByteBuf) {
- requests.read((DataStreamRequestByteBuf)msg, ctx,
proxies::getDataStreamOutput);
+ if (!(msg instanceof DataStreamRequestByteBuf)) {
+ LOG.error("Unexpected message class {}, ignoring ...",
msg.getClass().getName());
+ return;
}
+
+ final DataStreamRequestByteBuf current = (DataStreamRequestByteBuf)
msg;
+ currentRef.set(current);
+ requests.read(current, ctx, proxies::getDataStreamOutput);
+ }
+
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable
throwable) {
+ DataStreamManagement.sendException(currentRef.get(), throwable, ctx);
Review comment:
As shown in Netty's source code, it will try-catch `channelRead(..)`.
If there is an exception, it calls `invokeExceptionCaught(t)` and then
`exceptionCaught(..)`.
https://github.com/netty/netty/blob/944a0205862e32f1020647bbf4ef4eca5587446e/transport/src/main/java/io/netty/channel/AbstractChannelHandlerContext.java#L379
Since two channelRead(..) calls won't overlap, it is correct that our
exceptionCaught(..) is can read the current request from currentRef.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]