Skip to content

Commit b2126ac

Browse files
refactor: address code review - extract kill threshold constant and fix fd handling
Agent-Logs-Url: https://github.com/winnerspiros/osu/sessions/3b2e3212-5d99-4db3-855b-b2e0b0c2a186 Co-authored-by: winnerspiros <1675249+winnerspiros@users.noreply.github.com>
1 parent 093a72b commit b2126ac

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

osu.Android/Native/native_watchdog.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ volatile int g_dumpCount = 0;
9696
constexpr uint64_t kRedumpCooldownSec = 30;
9797
volatile uint64_t g_lastDumpMonotonicSec = 0;
9898

99+
// Kill threshold multiplier: process is killed after hangSeconds * this when
100+
// no managed heartbeat has EVER been observed (renderer init hung).
101+
constexpr uint64_t kKillThresholdMultiplier = 2;
102+
99103
// --------------------------------------------------------------------------
100104
// Async-signal-safe formatters / I/O.
101105
// --------------------------------------------------------------------------
@@ -531,7 +535,7 @@ void* watchdogMain(void* /*arg*/)
531535
// gives the renderer a generous window: the first dump fires at 1×
532536
// threshold for diagnostics, then we wait one more threshold period before
533537
// concluding the hang is unrecoverable.
534-
const uint64_t killThresholdSec = (uint64_t)g_hangSeconds * 2;
538+
const uint64_t killThresholdSec = (uint64_t)g_hangSeconds * kKillThresholdMultiplier;
535539

536540
for (;;)
537541
{
@@ -565,17 +569,20 @@ void* watchdogMain(void* /*arg*/)
565569
{
566570
// Write a final diagnostic before killing.
567571
int fd = openLogAppend();
568-
writeStr(fd, "\n=========================================================\n");
569-
writeStr(fd, "=== NATIVE WATCHDOG KILL ===\n");
570-
writeStr(fd, " reason = renderer init hang (no heartbeat ever observed after ");
571-
writeDec(fd, (long long)age);
572-
writeStr(fd, "s)\n");
573-
writeStr(fd, " action = killing process for safe-mode restart (OpenGL fallback)\n");
574-
writeStr(fd, " kill_threshold = ");
575-
writeDec(fd, (long long)killThresholdSec);
576-
writeStr(fd, "s\n");
577-
writeStr(fd, "=== END NATIVE WATCHDOG KILL ===\n\n");
578-
if (fd >= 0) close(fd);
572+
if (fd >= 0)
573+
{
574+
writeStr(fd, "\n=========================================================\n");
575+
writeStr(fd, "=== NATIVE WATCHDOG KILL ===\n");
576+
writeStr(fd, " reason = renderer init hang (no heartbeat ever observed after ");
577+
writeDec(fd, (long long)age);
578+
writeStr(fd, "s)\n");
579+
writeStr(fd, " action = killing process for safe-mode restart (OpenGL fallback)\n");
580+
writeStr(fd, " kill_threshold = ");
581+
writeDec(fd, (long long)killThresholdSec);
582+
writeStr(fd, "s\n");
583+
writeStr(fd, "=== END NATIVE WATCHDOG KILL ===\n\n");
584+
close(fd);
585+
}
579586

580587
__android_log_write(ANDROID_LOG_ERROR, WATCHDOG_LOG_TAG,
581588
"NATIVE WATCHDOG KILL — renderer init hung, killing for safe-mode OpenGL restart");

0 commit comments

Comments
 (0)