Skip to content
Open
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
2 changes: 1 addition & 1 deletion source/libs/transport/src/trans.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ void rpcClose(void* arg) {
return;
}
transCacheRemoveByRefId((int64_t)arg);
transRemoveExHandle(transGetInstMgt(), (int64_t)arg);
transReleaseExHandle(transGetInstMgt(), (int64_t)arg);
transRemoveExHandle(transGetInstMgt(), (int64_t)arg);
tInfo("end to close rpc");
return;
}
Expand Down
4 changes: 3 additions & 1 deletion source/libs/transport/src/transComm.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ void transCacheRemoveByRefId(int64_t refId) {
for (int32_t i = 0; i < transInstCache.num; i++) {
if (transInstCache.tran[i].refId == refId) {
atomic_store_32(&transInstCache.tran[i].remove, 1);
tDebug("trans %p removed by refId:%" PRId64 ", ref count:%d", transInstCache.tran[i].pTrans, refId,
atomic_load_32(&transInstCache.tran[i].ref));
while (atomic_load_32(&transInstCache.tran[i].ref) > 0) {
taosSsleep(1);
}
Expand All @@ -89,7 +91,7 @@ void transCacheReleaseByRefId(int64_t refId) {
for (int32_t i = 0; i < transInstCache.num; i++) {
if (transInstCache.tran[i].refId == refId) {
atomic_sub_fetch_32(&transInstCache.tran[i].ref, 1);
tDebug("trans %p acquire by refId:%" PRId64 ", ref count:%d", transInstCache.tran[i].pTrans, refId,
tDebug("trans %p released by refId:%" PRId64 ", ref count:%d", transInstCache.tran[i].pTrans, refId,
atomic_load_32(&transInstCache.tran[i].ref));
Comment on lines +94 to 95
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is a minor race condition in this logging. The reference count is decremented on the previous line, and then re-read here for the log message. In a highly concurrent environment, another thread could modify the reference count between these two operations, leading to a potentially misleading log message. To avoid this, it would be better to capture the return value of atomic_sub_fetch_32 and use it in this log message. For example:

const int32_t new_ref_count = atomic_sub_fetch_32(&transInstCache.tran[i].ref, 1);
tDebug("trans %p released by refId:%" PRId64 ", ref count:%d", transInstCache.tran[i].pTrans, refId, new_ref_count);

return;
}
Expand Down
Loading