Skip to content

Commit

Permalink
Add ByteBuf.touch(…) to aid buffer leak investigation #1164
Browse files Browse the repository at this point in the history
  • Loading branch information
mp911de committed Oct 30, 2019
1 parent 26d2b24 commit 541d3d0
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/io/lettuce/core/protocol/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void cancel() {
*/
public void encode(ByteBuf buf) {

buf.touch("Command.encode(…)");
buf.writeByte('*');
CommandArgs.IntegerArgument.writeInteger(buf, 1 + (args != null ? args.count() : 0));

Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/lettuce/core/protocol/CommandArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ public ByteBuffer getFirstEncodedKey() {
*/
public void encode(ByteBuf buf) {

buf.touch("CommandArgs.encode(…)");
for (SingularArgument singularArgument : singularArguments) {
singularArgument.encode(buf);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/lettuce/core/protocol/CommandEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, Object msg, boolean
@SuppressWarnings("unchecked")
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {

out.touch("CommandEncoder.encode(…)");
if (msg instanceof RedisCommand) {
RedisCommand<?, ?, ?> command = (RedisCommand<?, ?, ?>) msg;
encode(ctx, out, command);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/io/lettuce/core/protocol/CommandHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ private static boolean isWriteable(RedisCommand<?, ?, ?> command) {
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

ByteBuf input = (ByteBuf) msg;
input.touch("CommandHandler.read(…)");

if (!input.isReadable() || input.refCnt() == 0) {
logger.warn("{} Input not readable {}, {}", logPrefix(), input.isReadable(), input.refCnt());
Expand All @@ -558,6 +559,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
logger.trace("{} Buffer: {}", logPrefix(), input.toString(Charset.defaultCharset()).trim());
}

buffer.touch("CommandHandler.read(…)");
buffer.writeBytes(input);

decode(ctx, buffer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public boolean decode(ByteBuf buffer, RedisCommand<?, ?, ?> command, CommandOutp
int length, end;
ByteBuffer bytes;

buffer.touch("RedisStateMachine.decode(…)");
if (debugEnabled) {
logger.debug("Decode {}", command);
}
Expand Down

0 comments on commit 541d3d0

Please sign in to comment.