Skip to content

Commit 39096f6

Browse files
committed
polish: log atexit registration failure; trim comments
- Log a warning to stderr if std::atexit registration fails so the loss of the last-resort shm cleanup is visible; primary cleanup path is unaffected. - Tighten inline comments to explain only intent/constraints, not mechanics.
1 parent aa7708f commit 39096f6

3 files changed

Lines changed: 9 additions & 9 deletions

File tree

src/shm_manager.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ RegisterParentShmRegion(const std::string& shm_region_name)
6161
parent_shm_regions.insert(shm_region_name);
6262
}
6363
if (!parent_shm_atexit_registered.exchange(true)) {
64-
std::atexit(CleanupParentShmRegions);
64+
if (std::atexit(CleanupParentShmRegions) != 0) {
65+
std::cerr << "python_backend: failed to register atexit shm cleanup "
66+
"handler; relying on TerminateStub for cleanup"
67+
<< std::endl;
68+
}
6569
}
6670
}
6771

src/shm_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class SharedMemoryManager {
194194

195195
void SetDeleteRegion(bool delete_region);
196196

197-
// Remove the parent-owned shared memory region from the filesystem.
197+
// Idempotent: removes the parent-owned shm region and clears delete_region_.
198198
void RemoveShmRegion();
199199

200200
std::unique_ptr<CUDAMemoryPoolManager>& GetCUDAMemoryPoolManager()

src/stub_launcher.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -805,15 +805,12 @@ void
805805
StubLauncher::TerminateStub()
806806
{
807807
if (is_initialized_) {
808-
// Enforce stub_timeout_seconds_ as a single total budget across the
809-
// finalize wait and the subsequent process-exit wait; without this the
810-
// healthy teardown path could take up to 2 * stub_timeout_seconds_.
808+
// Single teardown budget: finalize + wait share stub_timeout_seconds_.
811809
bool force_kill = false;
812810
int64_t remaining_seconds = stub_timeout_seconds_;
813811
if (is_healthy_) {
814812
const int64_t total_timeout_ms = stub_timeout_seconds_ * 1000;
815-
// MessageQueue::Pop takes `int const&`; clamp to INT_MAX so a large
816-
// stub_timeout_seconds_ cannot silently narrow to a negative value.
813+
// Clamp to INT_MAX; MessageQueue::Pop takes int.
817814
const int pop_timeout_ms = static_cast<int>(std::min<int64_t>(
818815
total_timeout_ms,
819816
static_cast<int64_t>(std::numeric_limits<int>::max())));
@@ -983,8 +980,7 @@ StubLauncher::WaitForStubProcessWithTimeout(int64_t timeout_seconds)
983980
sleep(1);
984981
}
985982

986-
// The process may have exited during the final sleep window; re-check once
987-
// more so we don't force-kill an already-dead process.
983+
// Stub may have exited during the last sleep(1); recheck before killing.
988984
{
989985
int status;
990986
pid_t ret = waitpid(stub_pid_, &status, WNOHANG);

0 commit comments

Comments
 (0)