1.6 KiB
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
- Cargo builds successfully: "Finished dev profile"
- Binary starts: "Running target/debug/normogen-backend"
- Process exits silently (no logs, no errors)
- This repeats in a restart loop
Root Cause: Missing Runtime Output
The application is exiting before it can produce any output. This happens when:
-
main() function exits immediately
- Missing
#[tokio::main]attribute on async main - Main returns before async code runs
- Missing
-
Panic before logger initializes
- Env vars missing before dotenv loads
- Config error before logging setup
-
Docker command issue
- Using
cargo runwhich exits after compilation - Should use compiled binary directly
- Using
The Fix
Option 1: Fix Dockerfile Command (Recommended)
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.