GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Auto-port 5.0: Redis: Correctly release incomplete message on removal… · netty/netty@c31d687

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-redis/src
    • main/java/io/netty/handler/codec/redis
      • RedisArrayAggregator.java
    • test/java/io/netty/handler/codec/redis
      • RedisArrayAggregatorTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-redis/src/main/java/io/netty/handler/codec/redis/RedisArrayAggregator.java‎

Copy file name to clipboardExpand all lines: codec-redis/src/main/java/io/netty/handler/codec/redis/RedisArrayAggregator.java
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.netty.channel.ChannelHandlerContext;
1919
import io.netty.handler.codec.CodecException;
2020
import io.netty.handler.codec.MessageToMessageDecoder;
21+
import io.netty.handler.codec.PrematureChannelClosureException;
2122
import io.netty.util.ReferenceCountUtil;
2223
import io.netty.util.internal.UnstableApi;
2324

@@ -94,4 +95,26 @@ private static final class AggregateState {
9495
this.children = new ArrayList<RedisMessage>(length);
9596
}
9697
}
98+
99+
@Override
100+
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
101+
super.handlerRemoved(ctx);
102+
for (AggregateState state : depths) {
103+
for (RedisMessage message : state.children) {
104+
ReferenceCountUtil.safeRelease(message);
105+
}
106+
}
107+
depths.clear();
108+
}
109+
110+
@Override
111+
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
112+
super.channelInactive(ctx);
113+
114+
if (!depths.isEmpty()) {
115+
ctx.fireExceptionCaught(new PrematureChannelClosureException(
116+
"channel gone inactive with " + depths.size() +
117+
" messages still incomplete"));
118+
}
119+
}
97120
}
Collapse file

‎codec-redis/src/test/java/io/netty/handler/codec/redis/RedisArrayAggregatorTest.java‎

Copy file name to clipboard
+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2026 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License, version 2.0 (the
5+
* "License"); you may not use this file except in compliance with the License. You may obtain a
6+
* copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software distributed under the License
11+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
* or implied. See the License for the specific language governing permissions and limitations under
13+
* the License.
14+
*/
15+
16+
package io.netty.handler.codec.redis;
17+
18+
import io.netty.buffer.Unpooled;
19+
import io.netty.channel.embedded.EmbeddedChannel;
20+
import io.netty.handler.codec.PrematureChannelClosureException;
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.function.Executable;
23+
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
import static org.junit.jupiter.api.Assertions.assertFalse;
26+
import static org.junit.jupiter.api.Assertions.assertThrows;
27+
28+
public class RedisArrayAggregatorTest {
29+
30+
@Test
31+
void testDoesNotLeakOnClose() throws Exception {
32+
final EmbeddedChannel ch = new EmbeddedChannel(new RedisArrayAggregator());
33+
assertFalse(ch.writeInbound(new ArrayHeaderRedisMessage(2)));
34+
35+
FullBulkStringRedisMessage redisMessage = new FullBulkStringRedisMessage(Unpooled.buffer());
36+
assertEquals(1, redisMessage.refCnt());
37+
assertFalse(ch.writeInbound(redisMessage));
38+
assertEquals(1, redisMessage.refCnt());
39+
40+
assertThrows(PrematureChannelClosureException.class, new Executable() {
41+
@Override
42+
public void execute() throws Throwable {
43+
ch.finish();
44+
}
45+
});
46+
assertEquals(0, redisMessage.refCnt());
47+
}
48+
49+
@Test
50+
void testDoesNotLeakOnRemoval() throws Exception {
51+
EmbeddedChannel ch = new EmbeddedChannel(new RedisArrayAggregator());
52+
assertFalse(ch.writeInbound(new ArrayHeaderRedisMessage(2)));
53+
54+
FullBulkStringRedisMessage redisMessage = new FullBulkStringRedisMessage(Unpooled.buffer());
55+
assertEquals(1, redisMessage.refCnt());
56+
assertFalse(ch.writeInbound(redisMessage));
57+
assertEquals(1, redisMessage.refCnt());
58+
ch.pipeline().remove(RedisArrayAggregator.class);
59+
assertEquals(0, redisMessage.refCnt());
60+
assertFalse(ch.finish());
61+
}
62+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.