Engine robustness review fixes: crash-log repeats, teardown reserve, mutator gate, OOM dump safety
Native crash logger - Per-address slots keep hit counts and a last-write tick; a repeat relogs at powers of two, after 30 s, or for any non-AV code. The oldest noise slot is evicted when the table is full. - The logger checks its dedupe first, caches the module table, and opens the log handle once at install. Managed-noise bucket (coreclr, clrjit, System.Private.CoreLib). Main-thread queue - The action ring (ActionRing) rejects non-teardown work during a world transition and reserves its top 32 slots for teardown, so a stop is never lost behind held work. IsTeardownKind is shared by the enqueue and drain sides. ActionRing.TryPeekAt lets the cast drain's StopQueuedAtOrBefore walk the ring it no longer owns directly; the walk now checks every queued entry, since an entry's time is taken before the ring's lock. - MutatorGate: every AC-mutating helper opens with the same gate, AcMainThreadQueue.MustQueue(teardown: X); IsDraining and ShouldDefer added; teardown helpers are exempt from the hold. tools\check_offthread_mutators.py accepts MustQueue as the gate (it asks MainThreadGuard.IsOnMainThread itself). - MasteryFeed and VaultFeed pause during a transition. The heading slot drops a stale heading; the overlay select is kept. - RequestId never merges into an entry queued at or before the last transition hold; EnqueueRequestId returns false during a transition. - 0xF751 PlayerTeleport starts the 5 s settle window. - Cast slot: the queue time and Pending are published with Volatile.Write (a plain 64-bit store can tear on x86 and the drain reads both without the lock); the stop-wait flag is reset before the publishing store. Appraisals - Appraisal data survives a client release for 10 min (bounded at 4096); evicted on server delete (0xF747) and at session clear. 0xF747 is detected in SmartBox dispatch, independent of capture. Dumps - Dump start/end markers in the log; the launcher holds its wedge kill while a dump is in progress (DumpInProgressRule). The in-progress flag is cleared only when the writer thread exits. - The OOM dump triggers only on the main thread with AC's exact text, before stacks are built. Dumps are pruned only after a successful write, and other live clients' dumps are kept. CrashDump reads the file length before Delete. - ExitProcess/RtlExitUserProcess detours forward crash codes first. - The message box count is decremented first in a finally; 30 s safety reset when no box is visible on the main thread. - UsageStats counts the loader's CoreCLR fatal-error dumps (Logs\dumps\clr_*.dmp) as crashes alongside crash_*.dmp. Tests: EngineRobustnessTests, CrashLogFilterTests, UsageStatsTests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
55f7497065
commit
8c7201dc25
41 changed files with 1797 additions and 448 deletions
|
|
@ -123,7 +123,7 @@ internal static class CrashDump
|
|||
}
|
||||
}
|
||||
|
||||
// ── OUT OF MEMORY full-memory dump ──────────────────────────────────────
|
||||
// -- OUT OF MEMORY full-memory dump --------------------------------------
|
||||
|
||||
/// <summary>Full dumps kept in the Dumps folder (a full dump is about the size of the process).</summary>
|
||||
internal const int OutOfMemoryDumpsKept = 3;
|
||||
|
|
@ -157,34 +157,55 @@ internal static class CrashDump
|
|||
if (Interlocked.Exchange(ref _oomDumpLatch, 1) != 0) return;
|
||||
string why = "AC OUT OF MEMORY box: " + (reason ?? "?");
|
||||
_fullDumpInProgress = true;
|
||||
// The launcher reads this marker (DumpInProgressRule): MiniDumpWriteDump suspends every
|
||||
// thread, so the log goes silent for the whole dump, which would otherwise read as a dead
|
||||
// engine and get the client killed mid-dump.
|
||||
try { RynthLog.Error($"{DumpMarkerStarted} pid={Environment.ProcessId} - AC OUT OF MEMORY box; writing one full-memory dump before it shows."); }
|
||||
catch { }
|
||||
Thread? writer = null;
|
||||
try
|
||||
{
|
||||
RynthLog.Error("CrashDump: AC OUT OF MEMORY box opening - writing one full-memory dump before it shows.");
|
||||
Thread? writer = null;
|
||||
try
|
||||
writer = new Thread(() =>
|
||||
{
|
||||
writer = new Thread(() => WriteOutOfMemoryDumpCore(why)) { IsBackground = true, Name = "RynthCore.OomDump" };
|
||||
writer.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// No thread to be had (out of memory, after all): write it from this one.
|
||||
RynthLog.Error($"CrashDump: dump thread failed to start ({ex.GetType().Name}) - writing on the calling thread.");
|
||||
writer = null;
|
||||
}
|
||||
if (writer == null)
|
||||
WriteOutOfMemoryDumpCore(why);
|
||||
else if (!writer.Join(FullDumpWaitMs))
|
||||
RynthLog.Error($"CrashDump: full dump still writing after {FullDumpWaitMs / 1000}s - letting the box open.");
|
||||
// The flag stays up until the writer itself is done, even past a timed-out Join.
|
||||
try { WriteOutOfMemoryDumpCore(why); }
|
||||
finally { FinishFullDump(); }
|
||||
}) { IsBackground = true, Name = "RynthCore.OomDump" };
|
||||
writer.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
RynthLog.Error($"CrashDump: OOM dump failed {ex.GetType().Name}: {ex.Message}");
|
||||
// No thread to be had (out of memory, after all): write it from this one.
|
||||
try { RynthLog.Error($"CrashDump: dump thread failed to start ({ex.GetType().Name}) - writing on the calling thread."); } catch { }
|
||||
writer = null;
|
||||
}
|
||||
finally
|
||||
try
|
||||
{
|
||||
_fullDumpInProgress = false;
|
||||
if (writer == null)
|
||||
{
|
||||
try { WriteOutOfMemoryDumpCore(why); }
|
||||
finally { FinishFullDump(); }
|
||||
}
|
||||
else if (!writer.Join(FullDumpWaitMs))
|
||||
{
|
||||
RynthLog.Error($"CrashDump: full dump still writing after {FullDumpWaitMs / 1000}s - letting the box open (the writer keeps going).");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
try { RynthLog.Error($"CrashDump: OOM dump failed {ex.GetType().Name}: {ex.Message}"); } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Log line written before the OUT OF MEMORY full dump starts (read by the launcher).</summary>
|
||||
internal const string DumpMarkerStarted = RynthCore.Install.DumpInProgressRule.MarkerStarted;
|
||||
/// <summary>Log line written once the writer has finished, whatever the outcome.</summary>
|
||||
internal const string DumpMarkerEnded = RynthCore.Install.DumpInProgressRule.MarkerEnded;
|
||||
|
||||
private static void FinishFullDump()
|
||||
{
|
||||
_fullDumpInProgress = false;
|
||||
try { RynthLog.Error($"{DumpMarkerEnded} pid={Environment.ProcessId}."); } catch { }
|
||||
}
|
||||
|
||||
private static void WriteOutOfMemoryDumpCore(string reason)
|
||||
|
|
@ -193,22 +214,20 @@ internal static class CrashDump
|
|||
{
|
||||
string dir = OutOfMemoryDumpDirectory;
|
||||
Directory.CreateDirectory(dir);
|
||||
// Room for the new one first: keep the newest (Kept - 1), so the folder never holds
|
||||
// more than Kept full dumps even while this one is written.
|
||||
PruneDumps(dir, OutOfMemoryDumpPrefix, OutOfMemoryDumpsKept - 1);
|
||||
|
||||
string path = Path.Combine(dir, $"{OutOfMemoryDumpPrefix}{Environment.ProcessId}_{DateTime.Now:yyyyMMdd_HHmmss}.dmp");
|
||||
if (WriteDumpFile(path, DumpTypeFull, DumpTypeFullFallback, reason))
|
||||
{
|
||||
_fullDumpWrittenPath = path;
|
||||
RynthLog.Error($"CrashDump: OUT OF MEMORY full-memory dump: {path}");
|
||||
// Only after the new dump succeeded: a failed write never costs an older one.
|
||||
PruneDumps(dir, OutOfMemoryDumpPrefix, OutOfMemoryDumpsKept);
|
||||
}
|
||||
else
|
||||
{
|
||||
RynthLog.Error("CrashDump: OUT OF MEMORY full-memory dump FAILED; writing the small hang-type dump instead.");
|
||||
WriteSelfDump(reason, out _, "oom-small");
|
||||
}
|
||||
PruneDumps(dir, OutOfMemoryDumpPrefix, OutOfMemoryDumpsKept);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -216,7 +235,13 @@ internal static class CrashDump
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Deletes all but the newest <paramref name="keep"/> <paramref name="prefix"/>*.dmp files in <paramref name="dir"/>. Never throws.</summary>
|
||||
/// <summary>
|
||||
/// Deletes all but the newest <paramref name="keep"/> <paramref name="prefix"/>*.dmp files in
|
||||
/// <paramref name="dir"/>. The folder is shared by every client: a dump whose name carries
|
||||
/// the pid of ANOTHER process that is still running is never deleted (it may still be
|
||||
/// writing it, or about to report it), and is not counted against <paramref name="keep"/>.
|
||||
/// Never throws.
|
||||
/// </summary>
|
||||
internal static int PruneDumps(string dir, string prefix, int keep)
|
||||
{
|
||||
int deleted = 0;
|
||||
|
|
@ -224,13 +249,22 @@ internal static class CrashDump
|
|||
{
|
||||
FileInfo[] files = new DirectoryInfo(dir).GetFiles(prefix + "*.dmp");
|
||||
Array.Sort(files, (a, b) => b.LastWriteTimeUtc.CompareTo(a.LastWriteTimeUtc));
|
||||
for (int i = Math.Max(0, keep); i < files.Length; i++)
|
||||
int kept = 0;
|
||||
int self = Environment.ProcessId;
|
||||
foreach (FileInfo f in files)
|
||||
{
|
||||
int pid = DumpPid(f.Name, prefix);
|
||||
if (pid > 0 && pid != self && IsProcessAlive(pid))
|
||||
continue; // another live client's dump: not ours to delete
|
||||
if (kept < Math.Max(0, keep)) { kept++; continue; }
|
||||
string name = f.Name;
|
||||
long length = 0;
|
||||
try { length = f.Length; } catch { }
|
||||
try
|
||||
{
|
||||
files[i].Delete();
|
||||
f.Delete();
|
||||
deleted++;
|
||||
RynthLog.Info($"CrashDump: pruned old dump {files[i].Name} ({files[i].Length / (1024 * 1024)}MB).");
|
||||
RynthLog.Info($"CrashDump: pruned old dump {name} ({length / (1024 * 1024)}MB).");
|
||||
}
|
||||
catch { /* in use by a debugger, or already gone */ }
|
||||
}
|
||||
|
|
@ -238,4 +272,25 @@ internal static class CrashDump
|
|||
catch { }
|
||||
return deleted;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The pid in "prefix<pid>_...dmp", or 0.</summary>
|
||||
internal static int DumpPid(string fileName, string prefix)
|
||||
{
|
||||
if (!fileName.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) return 0;
|
||||
int start = prefix.Length, end = start;
|
||||
while (end < fileName.Length && char.IsDigit(fileName[end])) end++;
|
||||
return end > start && int.TryParse(fileName.AsSpan(start, end - start), out int pid) ? pid : 0;
|
||||
}
|
||||
|
||||
private static bool IsProcessAlive(int pid)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var p = System.Diagnostics.Process.GetProcessById(pid);
|
||||
return !p.HasExited;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}}
|
||||
|
|
|
|||
Loading…
Reference in a new issue