fix: infinit loop when handle exceed limit memory (#21556)

In some situation, _handle_mem_exceed_limit will alloc a large memory block, more than 5G. After add some log, we found that:

alloc memory was made in vector::insert_realloc
writers_to_reduce_mem's size is more than 8 million.
which indicated that an infinite loop was met in while (!tablets_mem_heap.empty()).
By reviewing codes, """ if (std::get<0>(tablet_mem_item)++ != std::get<1>(tablet_mem_item)) """ is wrong,
which must be """ if (++std::get<0>(tablet_mem_item) != std::get<1>(tablet_mem_item)) """.
In the original code, we will made ++ on end iterator, and then compare to end iterator, the behavior is undefined.
This commit is contained in:
shuke
2023-07-06 14:34:29 +08:00
committed by GitHub
parent 4d17400244
commit 06451c4ff1

View File

@ -394,7 +394,7 @@ void LoadChannelMgr::_handle_mem_exceed_limit() {
break;
}
tablets_mem_heap.pop();
if (std::get<0>(tablet_mem_item)++ != std::get<1>(tablet_mem_item)) {
if (++std::get<0>(tablet_mem_item) != std::get<1>(tablet_mem_item)) {
tablets_mem_heap.push(tablet_mem_item);
}
}