Server Troubleshooting
This guide covers common Tamandua server issues and their solutions. The server is built on Elixir/Phoenix with Broadway pipelines for telemetry processing.
Server Not Starting
Symptoms
- Server process exits immediately
- Service fails to start
- Health endpoint not responding
Diagnostic Steps
- Check service status
systemctl status tamandua-server
journalctl -u tamandua-server -n 100
- Check logs
tail -100 /var/log/tamandua-server/app.log
- Verify configuration
./bin/tamandua_server eval "IO.inspect(Application.get_all_env(:tamandua_server))"
Common Causes and Solutions
Missing Environment Variables
Error:** (RuntimeError) environment variable DATABASE_URL is missing
Solution:
Set required environment variables:
export DATABASE_URL="ecto://user:pass@localhost/tamandua_prod"
export REDIS_URL="redis://localhost:6379"
export SECRET_KEY_BASE="your-64-char-secret-key"
export ML_SERVICE_URL="http://localhost:8000"
# Or in /etc/tamandua-server/env
DATABASE_URL=ecto://user:pass@localhost/tamandua_prod
Port Already in Use
Error:** (Mint.TransportError) could not listen on port 4000: eaddrinuse
Solution:
# Find process using port
lsof -i :4000
netstat -tlnp | grep 4000
# Kill conflicting process or change port
export PHX_PORT=4001
Database Connection Failed at Startup
Error:** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused
Solution:
# Verify PostgreSQL is running
systemctl status postgresql
pg_isready -h localhost -p 5432
# Check credentials
psql -h localhost -U tamandua_user -d tamandua_prod -c "SELECT 1"
Migration Pending
Error:** (Ecto.MigrationError) migrations pending
Solution:
./bin/tamandua_server eval "TamanduaServer.Release.migrate()"
# Or
mix ecto.migrate
Invalid Configuration
Error:** (ArgumentError) invalid configuration for :tamandua_server
Solution:
- Validate configuration:
./bin/tamandua_server eval "TamanduaServer.Config.validate!()"
- Check
config/runtime.exssyntax - Verify all required keys are present
OTP Release Issues
Error:{"init terminating in do_boot", {undef,[{...}]}}
Solution:
- Rebuild release:
MIX_ENV=prod mix release --overwrite
- Verify Erlang/Elixir versions match build environment
Database Connection Errors
Symptoms
- Requests failing with database errors
- Slow queries
- Connection pool exhaustion
Diagnostic Steps
- Check PostgreSQL status
pg_isready
systemctl status postgresql
- Check connections
SELECT count(*) FROM pg_stat_activity WHERE datname = 'tamandua_prod';
SELECT * FROM pg_stat_activity WHERE datname = 'tamandua_prod' AND state != 'idle';
Common Causes and Solutions
Connection Pool Exhausted
Error:** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 5000ms
Solution:
- Increase pool size in configuration:
# config/runtime.exs
config :tamandua_server, TamanduaServer.Repo,
pool_size: String.to_integer(System.get_env("POOL_SIZE") || "20")
- Check for connection leaks:
SELECT pid, usename, application_name, state, query_start, query
FROM pg_stat_activity
WHERE datname = 'tamandua_prod' AND state != 'idle';
Too Many Connections
Error:** (Postgrex.Error) FATAL 53300 (too_many_connections) sorry, too many clients already
Solution:
- Check
max_connectionsin PostgreSQL:
SHOW max_connections;
- Increase limit in
postgresql.conf:
max_connections = 200
- Or reduce application pool sizes
Slow Queries
Symptom: High response times, timeout errors Solution:- Enable query logging:
config :tamandua_server, TamanduaServer.Repo,
log: :debug
- Check for missing indexes:
SELECT relname, seq_scan, idx_scan
FROM pg_stat_user_tables
WHERE seq_scan > idx_scan
ORDER BY seq_scan DESC;
- Analyze query plans:
EXPLAIN ANALYZE SELECT * FROM alerts WHERE status = 'open';
Connection Timeout
Error:** (DBConnection.ConnectionError) tcp connect (db.example.com:5432): timeout
Solution:
- Check network connectivity:
telnet db.example.com 5432
- Increase timeout:
config :tamandua_server, TamanduaServer.Repo,
connect_timeout: 30_000,
timeout: 60_000
- Check firewall/security group rules
SSL Required
Error:** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) no pg_hba.conf entry for host
Solution:
config :tamandua_server, TamanduaServer.Repo,
ssl: true,
ssl_opts: [
verify: :verify_peer,
cacertfile: "/path/to/ca.pem"
]
Redis Connection Issues
Symptoms
- Cache misses
- Session errors
- Rate limiting not working
- PubSub failures
Diagnostic Steps
- Check Redis status
redis-cli ping
systemctl status redis
- Check connection info
redis-cli info clients
redis-cli client list
Common Causes and Solutions
Connection Refused
Error:** (Redix.ConnectionError) tcp connect (localhost:6379): connection refused
Solution:
# Start Redis
systemctl start redis
# Check binding
grep "bind" /etc/redis/redis.conf
# Verify port
redis-cli -h localhost -p 6379 ping
Authentication Failed
Error:** (Redix.Error) NOAUTH Authentication required
Solution:
config :tamandua_server, :redis,
host: "localhost",
port: 6379,
password: System.get_env("REDIS_PASSWORD")
Memory Limit Reached
Error:** (Redix.Error) OOM command not allowed when used memory > 'maxmemory'
Solution:
- Check memory usage:
redis-cli info memory
- Increase memory limit in
redis.conf:
maxmemory 2gb
maxmemory-policy allkeys-lru
- Or clear unnecessary keys
Slow Redis Operations
Symptom: High latency on Redis operations Solution:- Check slow log:
redis-cli slowlog get 10
- Avoid expensive commands (KEYS, SMEMBERS on large sets)
- Enable pipelining for batch operations
Redis Cluster Connection
Error:** (Redix.Error) MOVED 12345 node2:6379
Solution:
Use cluster-aware client:
config :tamandua_server, :redis,
cluster: [
[host: "node1", port: 6379],
[host: "node2", port: 6379],
[host: "node3", port: 6379]
]
Memory Issues
Symptoms
- Server process killed by OOM
- Degraded performance
- Swap usage high
Diagnostic Steps
- Check memory usage
free -m
ps aux --sort=-%mem | head -10
- Check BEAM memory
:erlang.memory()
:recon.bin_leak(10)
Common Causes and Solutions
ETS Table Growth
Symptom: Memory steadily increasing Solution:- Check ETS table sizes:
:ets.all() |> Enum.map(fn t -> {t, :ets.info(t, :size), :ets.info(t, :memory)} end) |> Enum.sort_by(&elem(&1, 2), :desc) |> Enum.take(10)
- Implement TTL for cache tables
- Review agent registry cleanup
Process Heap Growth
Symptom: Individual processes consuming large memory Solution:- Find large processes:
:recon.proc_count(:memory, 10)
- Check for mailbox backlog:
:recon.proc_count(:message_queue_len, 10)
- Implement process recycling
Binary Memory
Symptom: High binary memory, not being collected Solution:- Check binary memory:
:erlang.memory(:binary)
- Force GC on suspected processes:
:erlang.garbage_collect(pid)
- Add periodic GC triggers
Atom Table Exhaustion
Error:** (SystemLimitError) a][] system limit has been reached
Solution:
- Increase atom limit:
# In vm.args or release
+t 5000000
- Avoid dynamic atom creation from user input
Large Queries
Symptom: Memory spikes during queries Solution:- Use streaming for large result sets:
Repo.stream(query) |> Stream.each(&process/1) |> Stream.run()
- Add LIMIT to queries
- Use pagination
Broadway Pipeline Errors
Symptoms
- Telemetry not being processed
- Events queued but not consumed
- Detection delays
Diagnostic Steps
- Check pipeline status
# In IEx console
TamanduaServer.Telemetry.Ingestor.status()
Broadway.all_running()
- Check RabbitMQ queues
rabbitmqctl list_queues name messages consumers
Common Causes and Solutions
RabbitMQ Connection Failed
Error:** (AMQP.ConnectionError) cannot connect to RabbitMQ: econnrefused
Solution:
# Start RabbitMQ
systemctl start rabbitmq-server
# Check status
rabbitmqctl status
# Verify credentials
rabbitmqctl authenticate_user tamandua password123
Queue Not Declared
Error:** (AMQP.Error) no queue 'telemetry' in vhost '/'
Solution:
# Declare queue manually
rabbitmqadmin declare queue name=telemetry durable=true
# Or run setup
./bin/tamandua_server eval "TamanduaServer.Release.setup_queues()"
Consumer Crashed
Error:[error] Broadway processor crashed: ** (ArgumentError) invalid telemetry event
Solution:
- Check dead letter queue for failed messages:
rabbitmqctl list_queues name=telemetry.dlq messages
- Review message format
- Add error handling in processor
Backpressure/Slow Processing
Symptom: Queue depth increasing Solution:- Check consumer count:
Broadway.producer_names(TamanduaServer.Telemetry.Ingestor)
- Increase concurrency:
config :tamandua_server, TamanduaServer.Telemetry.Ingestor,
processors: [
default: [concurrency: 10]
],
batchers: [
default: [concurrency: 5, batch_size: 100]
]
- Scale horizontally with more nodes
Message Acknowledgment Issues
Error:[warning] Message not acknowledged within timeout
Solution:
- Increase ack timeout:
config :tamandua_server, TamanduaServer.Telemetry.Ingestor,
producers: [
default: [
module: {BroadwayRabbitMQ.Producer, [
ack_timeout: 60_000
]}
]
]
- Check for blocking operations in processor
Pipeline Restart Loop
Symptom: Pipeline continuously restarting Solution:- Check supervisor logs:
grep "restarting" /var/log/tamandua-server/app.log
- Review crash reasons in logs
- Implement circuit breaker pattern
Phoenix Channel Issues
Symptoms
- Agents cannot connect via WebSocket
- Channels crash
- Message delivery failures
Common Causes and Solutions
Channel Process Crashed
Error:[error] GenServer #PID<0.1234.0> terminating
** (RuntimeError) agent channel crashed
Solution:
- Review channel logs
- Add error handling in channel callbacks
- Implement supervision for channels
Too Many Connections
Error:[warning] Too many connections, rejecting new WebSocket
Solution:
- Check connection limit:
length(Phoenix.Tracker.list(TamanduaServer.AgentTracker, "agents:lobby"))
- Increase limits:
config :tamandua_server, TamanduaServerWeb.Endpoint,
http: [
transport_options: [max_connections: 100_000]
]
- Scale horizontally
Presence/Tracker Issues
Error:[error] Phoenix.Tracker failed to sync
Solution:
- Check node connectivity:
Node.list()
- Verify PubSub configuration
- Check Redis PubSub adapter
Performance Optimization
General Optimization Tips
- Enable Erlang scheduler binding
# In vm.args
+sbt db
- Tune garbage collection
+hms 8192
+hmbs 8192
- Enable JIT (OTP 24+)
ERL_FLAGS="+JMsingle true"
Monitoring Recommendations
# Add telemetry handlers
:telemetry.attach_many("tamandua-metrics", [
[:tamandua, :repo, :query],
[:tamandua, :broadway, :processor, :stop],
[:phoenix, :channel_handled]
], &handle_event/4, nil)
Next Steps
- Agent Troubleshooting - Agent connectivity issues
- Network Troubleshooting - Network and TLS problems
- Detection Troubleshooting - Detection rule issues
- Troubleshooting Overview - General diagnostic tools