-
-
Notifications
You must be signed in to change notification settings - Fork 78
Open
Description
I found a problem, the packet was sent and returned success promise, but the server never received any packet about this.
Success:
02e3ca0f-433f-4f10-af9f-7af4178c81f2|1741440585811
true
ACTIVE
PREREAD
!!!
WROTE
!!!
WROTE
!!!
WROTE
!!!
WROTE
Fail:
234fd7ce-dcf6-42c6-acc0-76253471216c|1741440589633
true
ACTIVE
PREREAD
!!!
WROTE
Code1:
System.out.println(UUID.randomUUID() + "|" + System.currentTimeMillis());
System.out.println(ch.isActive());
ch.pipeline().addLast("hackfix",new ChannelInboundHandlerAdapter(){
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
System.out.println("PREREAD");
super.channelRead(ctx, msg);
}
public void channelActive(ChannelHandlerContext ctx) throws Exception {
ctx.read();
System.out.println("ACTIVE");
super.channelActive(ctx);
}
});
handleProxyAdded(ch);
Code2:
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof ByteBuf) {
ByteBuf byteBuf = (ByteBuf) msg;
if (closed) {
Shared.rel(byteBuf);
return;
}
if (channel == null) {
// 添加空指针防护
Queue<ByteBuf> localBuffers = this.buffers;
if (localBuffers != null) {
System.out.println("CACHED");
localBuffers.offer(byteBuf);
} else {
Shared.rel(byteBuf); // 直接释放
}
return;
}
System.out.println("!!!");
channel.eventLoop().execute(() -> {
if (channel.isOpen()) {
channel.writeAndFlush(msg).addListener(i -> {
System.out.println("WROTE");
if (!i.isSuccess()) {
Shared.rel(byteBuf); // 写入失败时释放
stopLogic(channel);
stopLogic(ctx.channel());
markClosed();
}
});//必须立马刷出, 否则会出现一些神奇的问题.
} else {
Shared.rel(byteBuf);
}
});
} else {
super.channelRead(ctx, msg);
}
//不可能进入下一步retain
//super.channelRead(ctx, msg);
}
// thanks
Metadata
Metadata
Assignees
Labels
No labels