Troubleshooting
This guide covers common issues encountered when deploying and running Dharini.
Docker Issues
Section titled “Docker Issues”Containers Won’t Start
Section titled “Containers Won’t Start”Problem: Services fail to start or immediately exit
Check service status:
docker ps -adocker logs backenddocker logs frontendCommon causes:
-
Port conflicts - Another service using ports 3000, 4000, 5432
Terminal window # Check what's using a portsudo lsof -i :4000# Change ports in docker-compose.yml if needed -
Environment variables missing
Terminal window # Verify .env file exists and has required variablescat .env | grep DB_HOST -
Docker daemon not running
Terminal window sudo systemctl status dockersudo systemctl start docker
Backend Container Restarting
Section titled “Backend Container Restarting”Problem: Backend container in restart loop
Check logs:
docker logs backend --tail 100Common issues:
-
Database connection failed
- Verify
DB_HOST,DB_PORT,DB_USERNAME,DB_PASSWORDin.env - For RDS, ensure SSL is enabled (automatic in production)
- Check RDS security group allows EC2 access
- Verify
-
Missing environment variables
- Check backend logs for “undefined” errors
- Ensure all required variables are set
-
Redis connection failed
- Verify Redis container is running:
docker ps | grep redis - Check
REDIS_HOST=redisin.env
- Verify Redis container is running:
Frontend Container Unhealthy
Section titled “Frontend Container Unhealthy”Problem: Frontend shows as “unhealthy” status
This is often normal during:
- Initial build
- After code changes
- Server Action cache mismatches
Solutions:
-
Wait 1-2 minutes - Health check may pass after warm-up
-
Rebuild frontend:
Terminal window docker compose --profile production restart frontend -
Clear browser cache - Hard refresh (
Ctrl+Shift+R) -
Full rebuild:
Terminal window docker compose --profile production downdocker compose --profile production up -d --build
Database Issues
Section titled “Database Issues”Cannot Connect to RDS
Section titled “Cannot Connect to RDS”Problem: “no pg_hba.conf entry for host” or connection timeout
Solutions:
-
Use SSL for RDS connections:
Terminal window PGSSLMODE=require psql -h your-rds-endpoint -U postgres -d postgres -
Check security group:
- RDS security group must allow port 5432 from EC2
- Verify EC2 security group ID or private IP is allowed
-
Verify RDS endpoint:
Terminal window # Test DNS resolutionnslookup your-database-instance.xxxxxxxxx.region.rds.amazonaws.com# Test connectivitync -zv your-database-instance.xxxxxxxxx.region.rds.amazonaws.com 5432 -
Check credentials:
- Verify username and password are correct
- Try connecting from another tool (pgAdmin, DBeaver)
PostGIS Extension Missing
Section titled “PostGIS Extension Missing”Problem: Migrations fail with “type ‘geometry’ does not exist”
Solution:
Connect to RDS and install PostGIS:
CREATE EXTENSION IF NOT EXISTS postgis;CREATE EXTENSION IF NOT EXISTS postgis_topology;CREATE EXTENSION IF NOT EXISTS "uuid-ossp";Migration Failures
Section titled “Migration Failures”Problem: npm run migration:run fails
Check:
-
View detailed error:
Terminal window docker logs backend -f -
Verify database connection:
Terminal window docker exec -it backend env | grep DB_ -
Check migration table:
SELECT * FROM migrations; -
Force rerun (if migration was partially applied):
DELETE FROM migrations WHERE name = 'FailedMigration';
Network and Nginx Issues
Section titled “Network and Nginx Issues”502 Bad Gateway
Section titled “502 Bad Gateway”Problem: Nginx returns 502 error
Causes:
-
Backend not running:
Terminal window docker ps | grep backenddocker logs backend -
Wrong upstream IP in Nginx config:
Terminal window # Verify EC2 private IPhostname -I# Update nginx config to matchsudo nano /etc/nginx/sites-available/dharini-prod -
Firewall blocking ports:
Terminal window # Check if ports are listeningsudo netstat -tulpn | grep -E ':(3000|4000|3001)'
504 Gateway Timeout
Section titled “504 Gateway Timeout”Problem: Requests time out
Solutions:
-
Increase Nginx timeout:
location /api/ {proxy_read_timeout 300;proxy_connect_timeout 300;proxy_send_timeout 300;# ... other settings} -
Check backend performance:
Terminal window docker stats backend
SSL Certificate Errors
Section titled “SSL Certificate Errors”Problem: Certificate not working or expired
Solutions:
-
Test renewal:
Terminal window sudo certbot renew --dry-run -
Force renewal:
Terminal window sudo certbot renew --force-renewal -
Regenerate certificate:
Terminal window sudo certbot --nginx -d your-domain.com
API 404 Errors
Section titled “API 404 Errors”Problem: /api/ requests return 404
Check:
-
Nginx path configuration:
# Strips /api/ prefixlocation /api/ {proxy_pass http://YOUR_PRIVATE_IP:4000/; # Trailing slash important!} -
Backend routes:
- Backend should define routes as
/users, not/api/users - Nginx strips
/api/before forwarding
- Backend should define routes as
-
Test directly:
Terminal window # Bypass Nginx - test backend directlycurl http://localhost:4000/users
Performance Issues
Section titled “Performance Issues”High CPU Usage
Section titled “High CPU Usage”Check resource usage:
docker statsCommon causes:
- Database queries - Check slow query log
- Infinite loops in background jobs
- Memory leaks - Monitor over time
Solutions:
- Scale EC2 instance - Upgrade to larger instance type
- Optimize queries - Add indexes, use EXPLAIN ANALYZE
- Restart services:
Terminal window docker compose --profile production restart
Out of Memory
Section titled “Out of Memory”Problem: Services crash with OOM errors
Check memory:
free -hdocker statsSolutions:
-
Increase EC2 instance memory
-
Add swap space (temporary):
Terminal window sudo fallocate -l 2G /swapfilesudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfile -
Reduce Docker memory limits in docker-compose.yml
Slow API Responses
Section titled “Slow API Responses”Debug:
-
Check database performance:
SELECT * FROM pg_stat_statements ORDER BY mean_time DESC LIMIT 10; -
Monitor RDS metrics in CloudWatch
-
Check Redis connectivity:
Terminal window docker exec -it redis redis-cli ping
Application Issues
Section titled “Application Issues”Login Not Working
Section titled “Login Not Working”Problem: Cannot log in with phone/OTP
Check:
-
Super admin user exists:
SELECT * FROM users WHERE designation = 'super-admin'; -
OTP service configured:
- Check
SENDGRID_API_KEYorGMAIL_USER/GMAIL_PASS - View backend logs for email send errors
- Check
-
Database connection:
Terminal window docker logs backend | grep -i "database"
File Upload Failing
Section titled “File Upload Failing”Problem: Cannot upload images or files
Check:
-
S3 credentials:
Terminal window # Test from backend containerdocker exec -it backend env | grep S3_ -
S3 bucket permissions:
- Verify IAM user has PutObject permission
- Check bucket policy
-
File size limits:
- Nginx:
client_max_body_size - Application:
MAX_FILE_ALLOW_UPLOAD
- Nginx:
-
Backend logs:
Terminal window docker logs backend | grep -i "upload"
Maps Not Loading
Section titled “Maps Not Loading”Problem: Maps or geospatial features not working
Check:
-
PostGIS installed:
SELECT PostGIS_version(); -
Spatial data:
SELECT id, ST_AsText(location) FROM sites LIMIT 5; -
Frontend map library loaded (check browser console)
Deployment Issues
Section titled “Deployment Issues”Git Pull Fails
Section titled “Git Pull Fails”Problem: Cannot pull latest code
Solutions:
-
Stash local changes:
Terminal window git stashgit pull origin demogit stash pop -
Force pull (discards local changes):
Terminal window git fetch origingit reset --hard origin/demo
Docker Build Fails
Section titled “Docker Build Fails”Problem: docker compose build fails
Common issues:
-
Disk space full:
Terminal window df -hdocker system prune -a -
Network issues downloading packages:
Terminal window # Retry with verbose outputdocker compose build --no-cache --progress=plain -
Dockerfile errors - Check backend/frontend Dockerfile
Monitoring and Logs
Section titled “Monitoring and Logs”View All Logs
Section titled “View All Logs”# All servicesdocker compose logs -f
# Specific servicedocker logs -f backenddocker logs -f frontend --tail 100
# Since specific timedocker logs backend --since 30mSystem Resources
Section titled “System Resources”# Disk usagedf -hdu -sh /var/lib/docker
# Memoryfree -h
# Docker statsdocker stats
# Processestophtop # if installedNetwork Debugging
Section titled “Network Debugging”# Test port connectivitync -zv your-domain.com 443
# DNS resolutionnslookup your-domain.com
# Trace routetraceroute your-domain.com
# Check listening portssudo netstat -tulpnGetting Help
Section titled “Getting Help”If issues persist:
- Check logs for specific error messages
- Search issues on GitHub: https://github.com/dsih-artpark/dharini/issues
- Create new issue with:
- Error logs
- Environment details (OS, Docker version)
- Steps to reproduce
- Contact the development team
Preventive Measures
Section titled “Preventive Measures”- Regular backups - Database and configuration
- Monitor disk space - Set up alerts
- Update regularly - Pull latest code weekly
- Test in staging before production updates
- Document changes to configuration
- Monitor logs for errors and warnings
Quick Fixes Checklist
Section titled “Quick Fixes Checklist”When something breaks, try these in order:
- ☐ Check Docker containers:
docker ps - ☐ View logs:
docker logs backend - ☐ Restart services:
docker compose restart - ☐ Check .env file variables
- ☐ Verify database connection
- ☐ Test Nginx config:
sudo nginx -t - ☐ Check security groups (AWS)
- ☐ Review recent changes:
git log - ☐ Rebuild if needed:
docker compose up -d --build - ☐ Check disk space:
df -h