Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INLONG-11717][SDK] Add out-of-bounds check when in getClientByRoundRobin() #11718

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class DefClientMgr implements ConfigHolder {
private static final Logger logger = LoggerFactory.getLogger(DefClientMgr.class);
private static final LogCounter logCounter = new LogCounter(10, 100000, 60 * 1000L);
private static final LogCounter updConExptCnt = new LogCounter(10, 100000, 60 * 1000L);
private static final LogCounter indexExptCnt = new LogCounter(10, 100000, 60 * 1000L);
private static final LogCounter exptCounter = new LogCounter(10, 100000, 60 * 1000L);
private static final byte[] hbMsgBody = ProxyUtils.getLocalIp().getBytes(StandardCharsets.UTF_8);

Expand Down Expand Up @@ -197,14 +198,24 @@ public Tuple2<SendResult, NettyClient> getClientByRoundRobin(MutableBoolean allC
if (curNodeSize == 0) {
return new Tuple2<>(SendResult.EMPTY_ACTIVE_NODE_SET, null);
}
int indexPos;
String curNode;
NettyClient client;
NettyClient backClient = null;
int nullClientCnt = 0;
int incFlightFailCnt = 0;
int startPos = reqSendIndex.getAndIncrement();
for (int step = 0; step < curNodeSize; step++) {
curNode = curNodes.get(Math.abs(startPos++) % curNodeSize);
startPos = Math.abs(startPos + 1);
indexPos = startPos % curNodeSize;
if (indexPos >= curNodes.size()) {
if (indexExptCnt.shouldPrint()) {
logger.warn("IndexOutOfBounds, startPos={}, curNodeSize={}, indexPos={}, realSize={}",
startPos, curNodeSize, indexPos, curNodes.size());
}
continue;
}
curNode = curNodes.get(indexPos);
client = usingClientMaps.get(curNode);
if (client == null) {
nullClientCnt++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class TcpClientMgr implements ClientMgr {
private static final Logger logger = LoggerFactory.getLogger(TcpClientMgr.class);
private static final LogCounter sendExceptCnt = new LogCounter(10, 100000, 60 * 1000L);
private static final LogCounter updConExptCnt = new LogCounter(10, 100000, 60 * 1000L);
private static final LogCounter indexExptCnt = new LogCounter(10, 100000, 60 * 1000L);
private static final LogCounter exptCounter = new LogCounter(10, 100000, 60 * 1000L);
private static final LogCounter callbackExceptCnt = new LogCounter(10, 100000, 60 * 1000L);
private static final AtomicLong timerRefCnt = new AtomicLong(0);
Expand Down Expand Up @@ -326,14 +327,24 @@ public boolean getClientByRoundRobin(ProcessResult procResult) {
if (curNodeSize == 0) {
return procResult.setFailResult(ErrorCode.EMPTY_ACTIVE_NODE_SET);
}
int indexPos;
String curNode;
TcpNettyClient client;
TcpNettyClient back1thClient = null;
int nullClientCnt = 0;
int unWritableCnt = 0;
int startPos = reqSendIndex.getAndIncrement();
for (int step = 0; step < curNodeSize; step++) {
curNode = curNodes.get(Math.abs(startPos++) % curNodeSize);
startPos = Math.abs(startPos + 1);
indexPos = startPos % curNodeSize;
if (indexPos >= curNodes.size()) {
if (indexExptCnt.shouldPrint()) {
logger.warn("IndexOutOfBounds, startPos={}, curNodeSize={}, indexPos={}, realSize={}",
startPos, curNodeSize, indexPos, curNodes.size());
}
continue;
}
curNode = curNodes.get(indexPos);
client = usingClientMaps.get(curNode);
if (client == null) {
nullClientCnt++;
Expand Down
Loading