B2ALABS® - Smart API Gateway Platform
®
Documentation/Troubleshooting

Troubleshooting Guide

Common issues and their solutions based on real deployment experiences. All fixes verified and tested in production environments.

Quick Issue Lookup

Use Ctrl+F (Cmd+F on Mac) to search for error messages or symptoms on this page.

Database Issues

Database Password Authentication Failed

CRITICAL

Gateway in restart loop with error: "failed SASL auth (FATAL: password authentication failed)"

Root Cause

Config file values in config.yaml override environment variables. Hardcoded password in config.yaml overrides DB_PASSWORD env var.

Solution

  • 1Remove any password value from packages/gateway-core/configs/config.yaml
  • 2Ensure DB_PASSWORD environment variable is set correctly in .env file
  • 3Verify config.yaml has: # password: removed - use DB_PASSWORD environment variable
  • 4Restart gateway service: docker-compose restart gateway

Diagnostic Commands

Check current environment variable:

docker-compose exec gateway printenv | grep DB_PASSWORD

Verify database connectivity with psql:

docker-compose exec postgres psql -U b2alabs -d b2alabs -c "SELECT 1"
Reference: DOCKER-DEPLOYMENT-COMPLETE-2025-10-17.md - Root Cause #4

Database Migration "relation does not exist" Error

HIGH

Error: relation "users" does not exist when running init scripts

Root Cause

Init scripts try to INSERT data before schema is created by migrations

Solution

  • 1Disable init scripts in docker-compose.yml by removing or renaming them
  • 2Let gateway migrations create schema first on startup
  • 3After gateway starts successfully, run seed scripts manually if needed
  • 4Proper order: 1) Start database 2) Run migrations 3) Seed data

Diagnostic Commands

CheckIcon migration status:

docker-compose exec gateway ./migrate -database "postgres://..." -path ./migrations version

Run migrations manually:

cd packages/gateway-core && make migrate-up
Reference: DOCKER-DEPLOYMENT-COMPLETE-2025-10-17.md - Issue #3

PostgreSQL Connection Timeout

MEDIUM

Gateway fails to start with "connection timeout" or "connection refused"

Root Cause

PostgreSQL takes 10-15 seconds to fully initialize after container starts

Solution

  • 1Wait 15-20 seconds after starting postgres before starting gateway
  • 2Use docker-compose wait or health checks
  • 3Gateway will retry connection automatically
  • 4CheckIcon PostgreSQL logs: docker-compose logs postgres

Diagnostic Commands

CheckIcon if PostgreSQL is accepting connections:

docker-compose exec postgres pg_isready -U b2alabs

View PostgreSQL logs for errors:

docker-compose logs postgres --tail 50

Database Connection Pool Exhausted

MEDIUM

Error: "connection pool timeout" or "too many connections"

Root Cause

Connection pool size too small for load, or connections not being released

Solution

  • 1Increase PostgreSQL max_connections in config
  • 2CheckIcon for long-running queries or hung connections
  • 3Verify connection pooling settings in GORM
  • 4Monitor connection metrics in Grafana

Diagnostic Commands

CheckIcon active connections:

docker-compose exec postgres psql -U b2alabs -d b2alabs -c "SELECT count(*) FROM pg_stat_activity"

Show all connections:

docker-compose exec postgres psql -U b2alabs -d b2alabs -c "SELECT pid, usename, application_name, state FROM pg_stat_activity"

Docker & Container Issues

Container Name Already in Use

LOW

Error: "The container name /b2alabs-gateway is already in use"

Root Cause

Old containers from previous runs still exist

Solution

  • 1Remove old containers: docker rm -f container_name
  • 2Or use docker-compose down to stop and remove all
  • 3Clean restart: docker-compose down -v && docker-compose up -d

Commands

List all containers (including stopped):

docker ps -a

Remove specific container:

docker rm -f b2alabs-gateway

Clean restart all services:

docker-compose down -v && docker-compose up -d

Service Build Failure

MEDIUM

Docker build fails with dependency errors or missing packages

Root Cause

Missing dependencies, network issues, or incorrect Dockerfile

Solution

  • 1CheckIcon Dockerfile for correct base image and dependencies
  • 2Clear Docker build cache: docker system prune -a
  • 3Verify network connectivity for package downloads
  • 4For optional services (like ml-service), skip if not needed

Commands

Build with no cache:

docker-compose build --no-cache gateway

View build logs:

docker-compose build gateway 2>&1 | tee build.log

Port Already in Use

LOW

Error: "bind: address already in use" for ports 3000, 8080, 5432, or 6379

Root Cause

Another service is using the required port

Solution

  • 1Find process using port: netstat -ano | findstr :8080 (Windows) or lsof -i :8080 (Linux/Mac)
  • 2Stop the conflicting service
  • 3Or change port in docker-compose.yml
  • 4Common conflicts: Local PostgreSQL (5432), Redis (6379), dev servers (3000, 8080)

Commands

Find process on port (Linux/Mac):

lsof -i :8080

Find process on port (Windows):

netstat -ano | findstr :8080

Kill process by PID:

kill -9 <PID>  # Linux/Mac
taskkill /PID <PID> /F  # Windows

Authentication Issues

JWT Token "Invalid Signature" Error

HIGH

API returns 401 Unauthorized with "invalid signature" even with valid token

Root Cause

JWT_SECRET changed between token creation and validation, or different secrets in different services

Solution

  • 1Ensure JWT_SECRET is the same across all services
  • 2Verify JWT_SECRET is at least 32 characters in production
  • 3Regenerate API keys after changing JWT_SECRET
  • 4CheckIcon config.go security validation (lines 327-356)

Commands

Verify JWT_SECRET is set:

docker-compose exec gateway printenv | grep JWT_SECRET

CheckIcon JWT_SECRET length:

docker-compose exec gateway sh -c 'echo -n "$JWT_SECRET" | wc -c'

Login Returns "User Not Found"

MEDIUM

POST /api/v1/auth/login returns 404 or "user not found" for valid credentials

Root Cause

User not created, email mismatch, or database not seeded

Solution

  • 1Register user first: POST /api/v1/auth/register
  • 2Verify user exists in database
  • 3CheckIcon email format (must be lowercase in database)
  • 4Ensure migrations ran successfully

Commands

List all users in database:

docker-compose exec postgres psql -U b2alabs -d b2alabs -c "SELECT id, email, name FROM users"

Create test user:

curl -X POST http://localhost:8080/api/v1/auth/register -H "Content-Type: application/json" -d '{"email":"test@example.com","password":"Test123!","name":"Test User"}'

API Key Authentication Fails

MEDIUM

Requests with X-API-KeyIcon header return 401 Unauthorized

Root Cause

API key not created, expired, or incorrect header format

Solution

  • 1Create API key via authenticated endpoint
  • 2Use header: X-API-KeyIcon: your_key_here
  • 3Verify API key is active and not revoked
  • 4CheckIcon permissions on the API key

Commands

Create API key (requires JWT token):

curl -X POST http://localhost:8080/api/v1/auth/api-keys -H "Authorization: Bearer YOUR_JWT" -H "Content-Type: application/json" -d '{"name":"My Key","permissions":["read","write"]}'

Test API key:

curl -X GET http://localhost:8080/health -H "X-API-KeyIcon: your_key_here"

Performance Issues

High Memory Usage / OOM Kills

HIGH

Gateway container restarts frequently with "OOMKilled" status

Root Cause

Memory leak, insufficient resources, or large cache size

Solution

  • 1Increase container memory limits in docker-compose.yml
  • 2CheckIcon for memory leaks in custom code
  • 3Reduce cache size (MEMORY_MAX_SIZE)
  • 4Use Redis cache instead of in-memory (CACHE_TYPE=redis)
  • 5Monitor with: docker stats

Diagnostic Commands

Monitor container memory usage:

docker stats --no-stream b2alabs-gateway

CheckIcon OOM kill events:

docker inspect b2alabs-gateway | grep -i oom

Slow API Response Times

MEDIUM

API requests taking >1 second to respond

Root Cause

CircleStackIcon queries not optimized, missing indexes, or network latency

Solution

  • 1Enable query logging: LOG_LEVEL=DEBUG
  • 2CheckIcon slow queries in PostgreSQL logs
  • 3Ensure caching is enabled: CACHING_ENABLED=true
  • 4Use CACHE_TYPE=redis for distributed caching
  • 5Monitor metrics in Grafana dashboard

Diagnostic Commands

Enable slow query logging:

docker-compose exec postgres psql -U b2alabs -d b2alabs -c "ALTER DATABASE b2alabs SET log_min_duration_statement = 1000"

View slow queries:

docker-compose logs postgres | grep "duration:"

General Debugging Tips

Essential commands and techniques for diagnosing issues

View Service Logs

# View all service logs
docker-compose logs -f

# View specific service
docker-compose logs -f gateway

# View last 50 lines
docker-compose logs --tail 50 gateway

# Follow logs in real-time
docker-compose logs -f --tail 100 gateway

CheckIcon Service Health

# CheckIcon all services status
docker-compose ps

# CheckIcon gateway health endpoint
curl http://localhost:8080/health

# CheckIcon web platform
curl http://localhost:3000

# CheckIcon database
docker-compose exec postgres pg_isready -U b2alabs

Interactive Container Access

# Access gateway shell
docker-compose exec gateway sh

# Access postgres
docker-compose exec postgres psql -U b2alabs -d b2alabs

# Access redis
docker-compose exec redis redis-cli

Need More Help?

Configuration Guide

Review all configuration options and environment variables

Contact Support

Reach out to our support team for assistance with complex issues

Still Having Issues?

If you can't find your issue here, check our community forums or contact support.

Was this page helpful?