The server consumes ~100% CPU on a single core even with zero players connected and not fully starting (the terminal isn't active although ports are opened) #2

Open
opened 2026-03-27 21:40:59 +02:00 by iAdrian · 0 comments
Owner

Root Cause

In Docker, stdin is closed (EOF) by default when stdin_open: true is not set. Console.ReadLine() returns null immediately and the
main command loop does continue — creating an infinite busy-loop.

Affected file: src/DiIiS-NA/Program.cs

// main loop
var line = Console.ReadLine(); // returns null instantly — stdin is EOF
if (line == null)
    continue; // ← infinite spin loop: ~1.3M read() syscalls/sec

Profiling

Diagnosed via /proc filesystem inside the container (no strace/perf needed):

┌─────────┬───────────────────┬──────────────────────────────────────┐
│ Metric │ Value │ Meaning │
├─────────┼───────────────────┼──────────────────────────────────────┤
│ wchan │ 0 │ thread never blocks — always running │
├─────────┼───────────────────┼──────────────────────────────────────┤
│ stime │ constantly rising │ kernel mode — syscalls │
├─────────┼───────────────────┼──────────────────────────────────────┤
│ syscr │ ~1.3M/sec │ read() calls per second │
├─────────┼───────────────────┼──────────────────────────────────────┤
│ rchar │ 33 bytes total │ all reads return EAGAIN/EOF │
└─────────┴───────────────────┴──────────────────────────────────────┘

Fix

Workaround (docker-compose): stdin_open: true keeps stdin open so ReadLine() blocks correctly.

## Root Cause In Docker, stdin is closed (EOF) by default when `stdin_open: true` is not set. `Console.ReadLine()` returns `null` immediately and the main command loop does `continue` — creating an infinite busy-loop. **Affected file:** `src/DiIiS-NA/Program.cs` ```csharp // main loop var line = Console.ReadLine(); // returns null instantly — stdin is EOF if (line == null) continue; // ← infinite spin loop: ~1.3M read() syscalls/sec ``` ## Profiling Diagnosed via /proc filesystem inside the container (no strace/perf needed): ┌─────────┬───────────────────┬──────────────────────────────────────┐ │ Metric │ Value │ Meaning │ ├─────────┼───────────────────┼──────────────────────────────────────┤ │ wchan │ 0 │ thread never blocks — always running │ ├─────────┼───────────────────┼──────────────────────────────────────┤ │ stime │ constantly rising │ kernel mode — syscalls │ ├─────────┼───────────────────┼──────────────────────────────────────┤ │ syscr │ ~1.3M/sec │ read() calls per second │ ├─────────┼───────────────────┼──────────────────────────────────────┤ │ rchar │ 33 bytes total │ all reads return EAGAIN/EOF │ └─────────┴───────────────────┴──────────────────────────────────────┘ ## Fix Workaround (docker-compose): stdin_open: true keeps stdin open so ReadLine() blocks correctly.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Gaming/blizzless-diiis#2
No description provided.