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:
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user