From ff18ced79dc6a3b91fd407621d06da350f91db48 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Mon, 24 Jan 2022 16:18:33 +0800 Subject: [PATCH] [TS-487](rpc): fix udp partial message chaos --- src/rpc/src/rpcUdp.c | 9 +++++++++ .../unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim | 4 ++-- tests/script/unique/migrate/mn2_vn2_repl2_rmVnodeDir.sim | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/rpc/src/rpcUdp.c b/src/rpc/src/rpcUdp.c index 7a46dbe5c3..f6bf59ae60 100644 --- a/src/rpc/src/rpcUdp.c +++ b/src/rpc/src/rpcUdp.c @@ -186,9 +186,11 @@ static void *taosRecvUdpData(void *param) { SUdpConn *pConn = param; struct sockaddr_in sourceAdd; ssize_t dataLen; + int32_t msgLen; unsigned int addLen; uint16_t port; SRecvInfo recvInfo; + SRpcHead *pHead; memset(&sourceAdd, 0, sizeof(sourceAdd)); addLen = sizeof(sourceAdd); @@ -216,6 +218,13 @@ static void *taosRecvUdpData(void *param) { continue; } + pHead = (SRpcHead *)msg; + msgLen = (int32_t)htonl((uint32_t)pHead->msgLen); + if (dataLen < msgLen) { + tError("%s recvfrom failed(%s): dataLen: %ld, msgLen: %d", pConn->label, strerror(errno), (long)dataLen, msgLen); + continue; + } + int32_t size = dataLen + tsRpcOverhead; char *tmsg = malloc(size); if (NULL == tmsg) { diff --git a/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim b/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim index 8d063020e7..7a716bd065 100644 --- a/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim +++ b/tests/script/unique/migrate/mn2_vn2_repl2_rmMnodeVnodeDir.sim @@ -51,7 +51,7 @@ sleep 1000 sql connect sleep 1000 sql create dnode $hostname2 -sleep 1000 +sleep 2000 print ============== step2: create database with replica 2, and create table, insert data $totalTableNum = 10 @@ -268,4 +268,4 @@ system sh/exec.sh -n dnode4 -s stop -x SIGINT system sh/exec.sh -n dnode5 -s stop -x SIGINT system sh/exec.sh -n dnode6 -s stop -x SIGINT system sh/exec.sh -n dnode7 -s stop -x SIGINT -system sh/exec.sh -n dnode8 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode8 -s stop -x SIGINT diff --git a/tests/script/unique/migrate/mn2_vn2_repl2_rmVnodeDir.sim b/tests/script/unique/migrate/mn2_vn2_repl2_rmVnodeDir.sim index 8f837b7e47..7581528d82 100644 --- a/tests/script/unique/migrate/mn2_vn2_repl2_rmVnodeDir.sim +++ b/tests/script/unique/migrate/mn2_vn2_repl2_rmVnodeDir.sim @@ -51,7 +51,7 @@ sleep 1000 sql connect sleep 1000 sql create dnode $hostname2 -sleep 1000 +sleep 2000 print ============== step2: create database with replica 2, and create table, insert data $totalTableNum = 10 @@ -266,4 +266,4 @@ system sh/exec.sh -n dnode4 -s stop -x SIGINT system sh/exec.sh -n dnode5 -s stop -x SIGINT system sh/exec.sh -n dnode6 -s stop -x SIGINT system sh/exec.sh -n dnode7 -s stop -x SIGINT -system sh/exec.sh -n dnode8 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode8 -s stop -x SIGINT -- GitLab