Skip to content

Troubleshooting

This guide covers common issues encountered when deploying and running Dharini.

Problem: Services fail to start or immediately exit

Check service status:

Terminal window
docker ps -a
docker logs backend
docker logs frontend

Common causes:

  1. Port conflicts - Another service using ports 3000, 4000, 5432

    Terminal window
    # Check what's using a port
    sudo lsof -i :4000
    # Change ports in docker-compose.yml if needed
  2. Environment variables missing

    Terminal window
    # Verify .env file exists and has required variables
    cat .env | grep DB_HOST
  3. Docker daemon not running

    Terminal window
    sudo systemctl status docker
    sudo systemctl start docker

Problem: Backend container in restart loop

Check logs:

Terminal window
docker logs backend --tail 100

Common issues:

  1. Database connection failed

    • Verify DB_HOST, DB_PORT, DB_USERNAME, DB_PASSWORD in .env
    • For RDS, ensure SSL is enabled (automatic in production)
    • Check RDS security group allows EC2 access
  2. Missing environment variables

    • Check backend logs for “undefined” errors
    • Ensure all required variables are set
  3. Redis connection failed

    • Verify Redis container is running: docker ps | grep redis
    • Check REDIS_HOST=redis in .env

Problem: Frontend shows as “unhealthy” status

This is often normal during:

  • Initial build
  • After code changes
  • Server Action cache mismatches

Solutions:

  1. Wait 1-2 minutes - Health check may pass after warm-up

  2. Rebuild frontend:

    Terminal window
    docker compose --profile production restart frontend
  3. Clear browser cache - Hard refresh (Ctrl+Shift+R)

  4. Full rebuild:

    Terminal window
    docker compose --profile production down
    docker compose --profile production up -d --build

Problem: “no pg_hba.conf entry for host” or connection timeout

Solutions:

  1. Use SSL for RDS connections:

    Terminal window
    PGSSLMODE=require psql -h your-rds-endpoint -U postgres -d postgres
  2. Check security group:

    • RDS security group must allow port 5432 from EC2
    • Verify EC2 security group ID or private IP is allowed
  3. Verify RDS endpoint:

    Terminal window
    # Test DNS resolution
    nslookup your-database-instance.xxxxxxxxx.region.rds.amazonaws.com
    # Test connectivity
    nc -zv your-database-instance.xxxxxxxxx.region.rds.amazonaws.com 5432
  4. Check credentials:

    • Verify username and password are correct
    • Try connecting from another tool (pgAdmin, DBeaver)

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";

Problem: npm run migration:run fails

Check:

  1. View detailed error:

    Terminal window
    docker logs backend -f
  2. Verify database connection:

    Terminal window
    docker exec -it backend env | grep DB_
  3. Check migration table:

    SELECT * FROM migrations;
  4. Force rerun (if migration was partially applied):

    DELETE FROM migrations WHERE name = 'FailedMigration';

Problem: Nginx returns 502 error

Causes:

  1. Backend not running:

    Terminal window
    docker ps | grep backend
    docker logs backend
  2. Wrong upstream IP in Nginx config:

    Terminal window
    # Verify EC2 private IP
    hostname -I
    # Update nginx config to match
    sudo nano /etc/nginx/sites-available/dharini-prod
  3. Firewall blocking ports:

    Terminal window
    # Check if ports are listening
    sudo netstat -tulpn | grep -E ':(3000|4000|3001)'

Problem: Requests time out

Solutions:

  1. Increase Nginx timeout:

    location /api/ {
    proxy_read_timeout 300;
    proxy_connect_timeout 300;
    proxy_send_timeout 300;
    # ... other settings
    }
  2. Check backend performance:

    Terminal window
    docker stats backend

Problem: Certificate not working or expired

Solutions:

  1. Test renewal:

    Terminal window
    sudo certbot renew --dry-run
  2. Force renewal:

    Terminal window
    sudo certbot renew --force-renewal
  3. Regenerate certificate:

    Terminal window
    sudo certbot --nginx -d your-domain.com

Problem: /api/ requests return 404

Check:

  1. Nginx path configuration:

    # Strips /api/ prefix
    location /api/ {
    proxy_pass http://YOUR_PRIVATE_IP:4000/; # Trailing slash important!
    }
  2. Backend routes:

    • Backend should define routes as /users, not /api/users
    • Nginx strips /api/ before forwarding
  3. Test directly:

    Terminal window
    # Bypass Nginx - test backend directly
    curl http://localhost:4000/users

Check resource usage:

Terminal window
docker stats

Common causes:

  1. Database queries - Check slow query log
  2. Infinite loops in background jobs
  3. Memory leaks - Monitor over time

Solutions:

  1. Scale EC2 instance - Upgrade to larger instance type
  2. Optimize queries - Add indexes, use EXPLAIN ANALYZE
  3. Restart services:
    Terminal window
    docker compose --profile production restart

Problem: Services crash with OOM errors

Check memory:

Terminal window
free -h
docker stats

Solutions:

  1. Increase EC2 instance memory

  2. Add swap space (temporary):

    Terminal window
    sudo fallocate -l 2G /swapfile
    sudo chmod 600 /swapfile
    sudo mkswap /swapfile
    sudo swapon /swapfile
  3. Reduce Docker memory limits in docker-compose.yml

Debug:

  1. Check database performance:

    SELECT * FROM pg_stat_statements ORDER BY mean_time DESC LIMIT 10;
  2. Monitor RDS metrics in CloudWatch

  3. Check Redis connectivity:

    Terminal window
    docker exec -it redis redis-cli ping

Problem: Cannot log in with phone/OTP

Check:

  1. Super admin user exists:

    SELECT * FROM users WHERE designation = 'super-admin';
  2. OTP service configured:

    • Check SENDGRID_API_KEY or GMAIL_USER/GMAIL_PASS
    • View backend logs for email send errors
  3. Database connection:

    Terminal window
    docker logs backend | grep -i "database"

Problem: Cannot upload images or files

Check:

  1. S3 credentials:

    Terminal window
    # Test from backend container
    docker exec -it backend env | grep S3_
  2. S3 bucket permissions:

    • Verify IAM user has PutObject permission
    • Check bucket policy
  3. File size limits:

    • Nginx: client_max_body_size
    • Application: MAX_FILE_ALLOW_UPLOAD
  4. Backend logs:

    Terminal window
    docker logs backend | grep -i "upload"

Problem: Maps or geospatial features not working

Check:

  1. PostGIS installed:

    SELECT PostGIS_version();
  2. Spatial data:

    SELECT id, ST_AsText(location) FROM sites LIMIT 5;
  3. Frontend map library loaded (check browser console)

Problem: Cannot pull latest code

Solutions:

  1. Stash local changes:

    Terminal window
    git stash
    git pull origin demo
    git stash pop
  2. Force pull (discards local changes):

    Terminal window
    git fetch origin
    git reset --hard origin/demo

Problem: docker compose build fails

Common issues:

  1. Disk space full:

    Terminal window
    df -h
    docker system prune -a
  2. Network issues downloading packages:

    Terminal window
    # Retry with verbose output
    docker compose build --no-cache --progress=plain
  3. Dockerfile errors - Check backend/frontend Dockerfile

Terminal window
# All services
docker compose logs -f
# Specific service
docker logs -f backend
docker logs -f frontend --tail 100
# Since specific time
docker logs backend --since 30m
Terminal window
# Disk usage
df -h
du -sh /var/lib/docker
# Memory
free -h
# Docker stats
docker stats
# Processes
top
htop # if installed
Terminal window
# Test port connectivity
nc -zv your-domain.com 443
# DNS resolution
nslookup your-domain.com
# Trace route
traceroute your-domain.com
# Check listening ports
sudo netstat -tulpn

If issues persist:

  1. Check logs for specific error messages
  2. Search issues on GitHub: https://github.com/dsih-artpark/dharini/issues
  3. Create new issue with:
    • Error logs
    • Environment details (OS, Docker version)
    • Steps to reproduce
  4. Contact the development team
  1. Regular backups - Database and configuration
  2. Monitor disk space - Set up alerts
  3. Update regularly - Pull latest code weekly
  4. Test in staging before production updates
  5. Document changes to configuration
  6. Monitor logs for errors and warnings

When something breaks, try these in order:

  1. ☐ Check Docker containers: docker ps
  2. ☐ View logs: docker logs backend
  3. ☐ Restart services: docker compose restart
  4. ☐ Check .env file variables
  5. ☐ Verify database connection
  6. ☐ Test Nginx config: sudo nginx -t
  7. ☐ Check security groups (AWS)
  8. ☐ Review recent changes: git log
  9. ☐ Rebuild if needed: docker compose up -d --build
  10. ☐ Check disk space: df -h