Skip to content

Commit

Permalink
Let object serialisation exceptions propagate in the Object Echo exam…
Browse files Browse the repository at this point in the history
…ple (netty#10807)

Motivation:
People may use the object serialisation example as a vehicle to test out sending their own objects across the wire.
If those objects are not actually serialisable for some reason, then we need to let the exception propagate so that this becomes obvious to people.

Modification:
Add a listener to the future that sends the first serialisable message, so that we ensure that any exceptions that shows up during serialisation becomes visible.
Without this, the state of the future that sent the first message was never checked or inspected anywhere.

Result:
Serialisation bugs in code derived from the Object Echo example are much easier to diagnose.

This fixes netty#10777
  • Loading branch information
chrisvest authored and 夏无影 committed Jul 8, 2022
1 parent 383ce78 commit dfe9955
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
*/
package io.netty.example.objectecho;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.ArrayList;
import java.util.List;

import static io.netty.channel.ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE;

/**
* Handler implementation for the object echo client. It initiates the
* ping-pong traffic between the object echo client and server by sending the
Expand All @@ -43,7 +47,8 @@ public ObjectEchoClientHandler() {
@Override
public void channelActive(ChannelHandlerContext ctx) {
// Send the first message if this handler is a client-side handler.
ctx.writeAndFlush(firstMessage);
ChannelFuture future = ctx.writeAndFlush(firstMessage);
future.addListener(FIRE_EXCEPTION_ON_FAILURE); // Let object serialisation exceptions propagate.
}

@Override
Expand Down

0 comments on commit dfe9955

Please sign in to comment.