rea-analysis-optimization
MOmorluto/rea485k近 7 天新增 9,215 个 star
Expert debugging methodology — systematic error diagnosis, root cause analysis, logging strategies, debugging tools, and problem-solving techniques that find bugs fast instead of guessing.
You are a detective investigating a crime scene. The bug is the crime. Your job is to find evidence, follow leads, and identify the root cause — not guess, not blame, not spray-and-pray fixes.
WHAT: What exactly happens? (error message, wrong behavior, crash)
WHEN: When does it happen? (specific input, time, condition)
WHERE: Where does it happen? (file, function, line)
HOW: How do you reproduce it? (steps to trigger)
SCOPE: How many people affected? (all users, some, one)
# Check logs
tail -100 /var/log/app/error.log
docker logs container_name --tail 100
# Check recent changes
git log --oneline -10
git diff HEAD~3
# Check system state
free -h # memory
df -h # disk
top # CPU
netstat -tlnp # ports
TypeError: Cannot read property 'x' of undefined
Diagnosis: Something that should exist doesn't. Fix chain:
ECONNREFUSED 127.0.0.1:5432
connect EHOSTUNREACH 10.0.0.1:3306
Diagnosis: Can't reach the service. Check list:
systemctl status <service> or docker psnetstat -tlnp | grep <port>ping <host>iptables -L or ufw status0.0.0.0 vs 127.0.0.1ETIMEDOUT: Connection timed out after 30000ms
Operation timed out after 5000ms
Diagnosis: Request took too long. Check list:
EXPLAIN ANALYZE the database queryping and tracerouteJavaScript heap out of memory
MemoryError: Unable to allocate memory
Diagnosis: Ran out of RAM. Check list:
# Compile with debug info
cargo build
# Run with RUST_BACKTRACE
RUST_BACKTRACE=1 cargo run
# Run with debug assertions
cargo test
# Use rust-gdb
rust-gdb target/debug/myapp
(gdb) run
(gdb) backtrace
(gdb) info locals
// Console debugging
console.log('variable:', variable);
console.table(arrayOfObjects);
console.time('operation');
// ... code ...
console.timeEnd('operation');
// Node.js inspector
node --inspect app.js
# Then open chrome://inspect in Chrome
// Chrome DevTools
// Sources tab → Breakpoints → Step through code
// Profiler tab → Record → Find hot functions
// Memory tab → Take heap snapshot → Compare
# Interactive debugging
import pdb; pdb.set_trace() # Python 3.6-
breakpoint() # Python 3.7+
# In debugger:
# n (next line)
# s (step into)
# c (continue)
# p variable (print)
# l (list source)
# q (quit)
# Better debugger: ipdb
import ipdb; ipdb.set_trace()
# Traceback inspection
import traceback
try:
risky_operation()
except Exception:
traceback.print_exc()
# Delve debugger
dlv debug main.go
(dlv) break main.main
(dlv) continue
(dlv) step
(dlv) print variable
(dlv) goroutines
(dlv) stack
# Race detector
go run -race main.go
go test -race ./...
ERROR — something broke, needs immediate attention
WARN — something unexpected, but not broken
INFO — normal operations worth recording
DEBUG — detailed info for troubleshooting
TRACE — extremely detailed, function-level
{
"timestamp": "2024-01-15T10:30:00Z",
"level": "error",
"message": "Failed to process payment",
"error": "Connection refused",
"user_id": "usr_123",
"order_id": "ord_456",
"amount": 99.99,
"provider": "stripe"
}
# Check DNS resolution
dig example.com
nslookup example.com
# Check connectivity
curl -v https://api.example.com/health
telnet api.example.com 443
# Capture traffic
tcpdump -i eth0 port 443
wireshark # GUI packet analyzer
# Test API endpoints
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "test"}' \
-v
# Find process using a port
lsof -i :3000
ss -tlnp | grep 3000
# strace a process
strace -p <pid> -e trace=network
# Check open file descriptors
ls -la /proc/<pid>/fd
# Check environment variables
cat /proc/<pid>/environ | tr '\0' '\n'
-- Check for locks
SELECT * FROM pg_locks WHERE NOT granted;
-- Check slow queries
SELECT * FROM pg_stat_activity WHERE state = 'active' AND query_start < NOW() - INTERVAL '5 minutes';
-- Check table sizes
SELECT relname, pg_size_pretty(pg_total_relation_size(relid))
FROM pg_catalog.pg_statio_user_tables
ORDER BY pg_total_relation_size(relid) DESC;
-- Check index usage
SELECT relname, indexrelname, idx_scan
FROM pg_stat_user_indexes
ORDER BY idx_scan ASC;
# Write a test that reproduces the bug
def test_user_email_uniqueness():
"""Regression: concurrent signups could create duplicate emails."""
create_user(email="[email protected]")
with pytest.raises(IntegrityError):
create_user(email="[email protected]")
# Validate inputs at boundaries
def process_order(order_data: dict) -> Order:
if not order_data.get("items"):
raise ValueError("Order must have at least one item")
if order_data["total"] < 0:
raise ValueError("Order total cannot be negative")
# ... proceed with processing
# Alert on conditions that caused the bug
if error_rate > 0.01:
alert("Error rate exceeded 1% threshold")
if response_time_p99 > 2000:
alert("P99 response time exceeded 2 seconds")
When you find a bug:
MOmorluto/rea485k近 7 天新增 9,215 个 star
MAmattpocock/skills336k近 7 天新增 5,004 个 star
MAmattpocock/skills336k近 7 天新增 5,004 个 star
MAmattpocock/skills336k近 7 天新增 5,004 个 star
MAmattpocock/skills336k近 7 天新增 5,004 个 star