normogen/backend/SILENT-CRASH-FIX.md

1.6 KiB

Backend Silent Crash - Root Cause & Fix

Problem

The backend container starts, compiles, runs the binary, then exits immediately with NO output.

Analysis

What We Know

  1. Cargo builds successfully: "Finished dev profile"
  2. Binary starts: "Running target/debug/normogen-backend"
  3. Process exits silently (no logs, no errors)
  4. This repeats in a restart loop

Root Cause: Missing Runtime Output

The application is exiting before it can produce any output. This happens when:

  1. main() function exits immediately

    • Missing #[tokio::main] attribute on async main
    • Main returns before async code runs
  2. Panic before logger initializes

    • Env vars missing before dotenv loads
    • Config error before logging setup
  3. Docker command issue

    • Using cargo run which exits after compilation
    • Should use compiled binary directly

The Fix

The issue is the Dockerfile uses cargo run which rebuilds every time. Change to run the compiled binary directly:

# In Dockerfile.dev, change:
CMD ["cargo run"]

# To:
CMD ["./target/debug/normogen-backend"]

Option 2: Add Debug Output to main.rs

Before anything in main(), add:

fn main() {
    eprintln!("NORMOGEN BACKEND STARTING...");
    // rest of code
}

Option 3: Fix Async Runtime

If using async, ensure:

#[tokio::main]
async fn main() {
    // your code
}

Immediate Action

Add eprintln! at the very start of main.rs to confirm code is running. If we see the eprintln, we know the issue is elsewhere. If we DON'T see it, the binary isn't even executing.