Skip to content

Commit

Permalink
fix keeper cmd file handler leak
Browse files Browse the repository at this point in the history
  • Loading branch information
lishanglin committed Sep 10, 2024
1 parent 7d8d789 commit f060eac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ReferenceFileRegion(FileChannel fileChannel, long position, long count, R


@Override
protected void deallocate() {
public void deallocate() {

try {
referenceFileChannel.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ctrip.xpipe.netty.filechannel.ReferenceFileRegion;
import com.ctrip.xpipe.redis.core.store.*;
import com.ctrip.xpipe.redis.keeper.monitor.KeeperMonitor;
import com.ctrip.xpipe.utils.CloseState;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import org.slf4j.Logger;
Expand Down Expand Up @@ -78,7 +79,14 @@ public void addCommandsListener(ReplicationProgress<?> progress, final CommandsL
}
getCommandStoreDelay().beginSend(listener, referenceFileRegion.getTotalPos());

ChannelFuture future = listener.onCommand(cmdReader.getCurCmdFile(), cmdReader.position(), referenceFileRegion);
ChannelFuture future = null;
try {
future = listener.onCommand(cmdReader.getCurCmdFile(), cmdReader.position(), referenceFileRegion);
} catch (CloseState.CloseStateException e) {
logger.info("[addCommandsListener][listener closed] deallocate fileRegion");
referenceFileRegion.deallocate();
throw e;
}

if(future != null){
CommandReader<ReferenceFileRegion> finalCmdReader = cmdReader;
Expand Down

0 comments on commit f060eac

Please sign in to comment.