fix(backend): Add debug output to diagnose silent crash
This commit is contained in:
parent
7221a8e280
commit
e5d0ae4fd1
3 changed files with 149 additions and 6 deletions
69
backend/SILENT-CRASH-FIX.md
Normal file
69
backend/SILENT-CRASH-FIX.md
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# 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
|
||||
|
||||
### 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:
|
||||
|
||||
```dockerfile
|
||||
# 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:
|
||||
```rust
|
||||
fn main() {
|
||||
eprintln!("NORMOGEN BACKEND STARTING...");
|
||||
// rest of code
|
||||
}
|
||||
```
|
||||
|
||||
### Option 3: Fix Async Runtime
|
||||
|
||||
If using async, ensure:
|
||||
```rust
|
||||
#[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.
|
||||
Loading…
Add table
Add a link
Reference in a new issue