Description
logApiAccess() in logger.js attempts a full MongoDB connection on every single API profile request with a 10-second serverSelectionTimeoutMS. If MongoDB is unreachable, every profile render is delayed by up to 10 seconds. There is no circuit breaker — once a connection fails, the next request repeats the entire 10-second wait.
This creates cascading latency: if MongoDB goes down, every subsequent profile request suffers a 10s delay before eventually succeeding or failing.
Steps to Reproduce
- Set an invalid MONGODB_URI
- Request /api/profile?username=octocat
- Observe ~10 second delay
- Request again — same 10 second delay repeats
Root Cause
src/utils/logger.js — connectToDatabase() doesn't cache failure state. The connectionAttempted variable on line 4 is declared but never read after being set.
Suggested Fix
Cache the failure state so that if a MongoDB connection attempt fails, subsequent requests within the same process skip the connection attempt entirely and log a warning instead of retrying.
Files to Modify
Description
logApiAccess() in logger.js attempts a full MongoDB connection on every single API profile request with a 10-second serverSelectionTimeoutMS. If MongoDB is unreachable, every profile render is delayed by up to 10 seconds. There is no circuit breaker — once a connection fails, the next request repeats the entire 10-second wait.
This creates cascading latency: if MongoDB goes down, every subsequent profile request suffers a 10s delay before eventually succeeding or failing.
Steps to Reproduce
Root Cause
src/utils/logger.js — connectToDatabase() doesn't cache failure state. The connectionAttempted variable on line 4 is declared but never read after being set.
Suggested Fix
Cache the failure state so that if a MongoDB connection attempt fails, subsequent requests within the same process skip the connection attempt entirely and log a warning instead of retrying.
Files to Modify