mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 21:21:37 +00:00
fix(shmem): fill the result of Monitor::GetDebugInfo()
- The function reserved each result vector and then wrote to result[segment][handle], past the end of the vector: it returned empty vectors and corrupted the heap - Append one entry per buffer, in the order of the buffer offset - Check the debug map for null before its first use - Name the map entries (segment id, offset, buffer) instead of .first and .second - Enable Monitor.GetDebugInfo (needs FAIRMQ_DEBUG_MODE) - Update the documentation page that described the defect Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -316,14 +316,9 @@ are static. They take a `ShmId` or a `SessionId` as the first argument. `PrintSh
|
|||||||
| [`RegionIsPresent(id, regionId)`](/api/fair/mq/shmem/Monitor/#RegionIsPresent) | Returns `true` if the region can be opened. |
|
| [`RegionIsPresent(id, regionId)`](/api/fair/mq/shmem/Monitor/#RegionIsPresent) | Returns `true` if the region can be opened. |
|
||||||
| [`GetFreeMemory(id, segmentId)`](/api/fair/mq/shmem/Monitor/#GetFreeMemory) | Returns the free bytes of a managed segment. Throws `MonitorError`. |
|
| [`GetFreeMemory(id, segmentId)`](/api/fair/mq/shmem/Monitor/#GetFreeMemory) | Returns the free bytes of a managed segment. Throws `MonitorError`. |
|
||||||
| [`PrintDebugInfo(id)`](/api/fair/mq/shmem/Monitor/#PrintDebugInfo) | Prints the messages in the segments. Needs `FAIRMQ_DEBUG_MODE`. |
|
| [`PrintDebugInfo(id)`](/api/fair/mq/shmem/Monitor/#PrintDebugInfo) | Prints the messages in the segments. Needs `FAIRMQ_DEBUG_MODE`. |
|
||||||
| [`GetDebugInfo(id)`](/api/fair/mq/shmem/Monitor/#GetDebugInfo) | Returns the messages in the segments. Needs `FAIRMQ_DEBUG_MODE`. See the caution below. |
|
| [`GetDebugInfo(id)`](/api/fair/mq/shmem/Monitor/#GetDebugInfo) | Returns the messages in the segments: for each segment ID, the offset, the PID of the creator, the size and the creation time of each message. Needs `FAIRMQ_DEBUG_MODE`. |
|
||||||
| [`RemoveObject(name)`](/api/fair/mq/shmem/Monitor/#RemoveObject), [`RemoveFileMapping()`](/api/fair/mq/shmem/Monitor/#RemoveFileMapping), [`RemoveQueue()`](/api/fair/mq/shmem/Monitor/#RemoveQueue), [`RemoveMutex()`](/api/fair/mq/shmem/Monitor/#RemoveMutex), [`RemoveCondition()`](/api/fair/mq/shmem/Monitor/#RemoveCondition) | Remove one object by its full name. Return `true` if it was removed. |
|
| [`RemoveObject(name)`](/api/fair/mq/shmem/Monitor/#RemoveObject), [`RemoveFileMapping()`](/api/fair/mq/shmem/Monitor/#RemoveFileMapping), [`RemoveQueue()`](/api/fair/mq/shmem/Monitor/#RemoveQueue), [`RemoveMutex()`](/api/fair/mq/shmem/Monitor/#RemoveMutex), [`RemoveCondition()`](/api/fair/mq/shmem/Monitor/#RemoveCondition) | Remove one object by its full name. Return `true` if it was removed. |
|
||||||
|
|
||||||
:::caution[GetDebugInfo()]
|
|
||||||
`GetDebugInfo()` has a known defect: it writes out of the bounds of its result vectors and returns
|
|
||||||
empty lists. Its test is disabled. Use `PrintDebugInfo()` or `fairmq-shmmonitor --debug`.
|
|
||||||
:::
|
|
||||||
|
|
||||||
The tool `fairmq-shmmonitor` also uses a `Monitor` object: the constructor
|
The tool `fairmq-shmmonitor` also uses a `Monitor` object: the constructor
|
||||||
[`Monitor()`](/api/fair/mq/shmem/Monitor/#Monitor) takes the shmId and the mode flags.
|
[`Monitor()`](/api/fair/mq/shmem/Monitor/#Monitor) takes the shmId and the mode flags.
|
||||||
[`CatchSignals()`](/api/fair/mq/shmem/Monitor/#CatchSignals) handles `SIGINT` and `SIGTERM`, and
|
[`CatchSignals()`](/api/fair/mq/shmem/Monitor/#CatchSignals) handles `SIGINT` and `SIGTERM`, and
|
||||||
|
|||||||
@@ -483,14 +483,13 @@ unordered_map<uint16_t, std::vector<BufferDebugInfo>> Monitor::GetDebugInfo(cons
|
|||||||
|
|
||||||
Uint16MsgDebugMapHashMap* debug = managementSegment.find<Uint16MsgDebugMapHashMap>(bipc::unique_instance).first;
|
Uint16MsgDebugMapHashMap* debug = managementSegment.find<Uint16MsgDebugMapHashMap>(bipc::unique_instance).first;
|
||||||
|
|
||||||
result.reserve(debug->size());
|
|
||||||
|
|
||||||
|
|
||||||
if (debug) {
|
if (debug) {
|
||||||
for (const auto& s : *debug) {
|
result.reserve(debug->size());
|
||||||
result[s.first].reserve(s.second.size());
|
for (const auto& [segmentId, buffers] : *debug) {
|
||||||
for (const auto& e : s.second) {
|
auto& infos = result[segmentId];
|
||||||
result[s.first][e.first] = BufferDebugInfo(e.first, e.second.fPid, e.second.fSize, e.second.fCreationTime);
|
infos.reserve(buffers.size());
|
||||||
|
for (const auto& [offset, buffer] : buffers) {
|
||||||
|
infos.emplace_back(offset, buffer.fPid, buffer.fSize, buffer.fCreationTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -100,11 +100,7 @@ TEST(Monitor, CleanupAfterNoCleanup)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FAIRMQ_DEBUG_MODE
|
#ifdef FAIRMQ_DEBUG_MODE
|
||||||
// Known defect: Monitor::GetDebugInfo() only reserves each result vector and
|
TEST(Monitor, GetDebugInfo)
|
||||||
// then writes to result[segment][handle], out of the bounds of the vector.
|
|
||||||
// It returns empty vectors and corrupts the heap. It also dereferences the
|
|
||||||
// debug map before its null check. Enable this test with the fix.
|
|
||||||
TEST(Monitor, DISABLED_GetDebugInfo)
|
|
||||||
{
|
{
|
||||||
ProgOptions config;
|
ProgOptions config;
|
||||||
auto const session = ShmConfig(config, false);
|
auto const session = ShmConfig(config, false);
|
||||||
|
|||||||
Reference in New Issue
Block a user