Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Troubleshooting

Common operational issues and how to resolve them.

Engine suspension

Symptoms: An engine shows “suspended” status on the /admin/log page, or search results suddenly exclude a particular source.

Cause: The rate limiter auto-suspends engines after repeated failures (timeouts, HTTP errors, empty results). Suspension uses exponential backoff – each successive failure doubles the cooldown period.

Diagnosis:

  1. Visit /admin/log (public) or /admin/health (owner). Suspended engines show a red “suspended” status badge.
  2. Check the server logs for lines like engine X: error ... or engine X: timeout.
  3. Verify the upstream engine is actually reachable: curl -I https://engine-url/.

Resolution:

  • Engines auto-recover once the backoff period expires and the next request succeeds.
  • Owner can force-unsuspend via the admin health dashboard.
  • If the engine requires an API key, verify the key is valid and not rate-limited.
  • For scraping-based engines (Google, Bing, Yahoo), verify the instance IP is not blocked. Rotating the IP or enabling deluxe mode (browser backend) may help.

PoW difficulty tuning

Symptoms: Users complain PoW takes too long, or bots are getting through too easily.

Configuration: Set pow-difficulty in config.kdl (default: 22 bits). Higher values require more computation:

  • 18-20: fast solve (~100ms), low bot resistance
  • 22-24: moderate (~500ms-2s), good balance for most instances
  • 26+: strong bot resistance, may frustrate users on slow devices

The server applies adaptive difficulty automatically: +1 bit above 100 requests/minute, +2 bits above 500 RPM. The base difficulty in config is the floor.

Tuning tips:

  • Monitor PoW success/fail rates on /admin/log (IQ stats section).
  • If PoW fails are very high, bots may be attempting brute force – raise difficulty.
  • If legitimate users report slow verification, lower the base or ensure the PoW JavaScript is loading correctly (check for CDN/proxy issues stripping scripts).

SQLite WAL growth

Symptoms: The 4got.db-wal file grows continuously, consuming disk space.

Cause: SQLite WAL (Write-Ahead Logging) mode checkpoints periodically, but under sustained write load the WAL file can grow before checkpointing catches up. The server opens the DB with _journal_mode=WAL&_busy_timeout=5000.

Resolution:

  1. Check WAL size: ls -lh data/4got.db-wal
  2. Force a checkpoint: sqlite3 data/4got.db 'PRAGMA wal_checkpoint(TRUNCATE);'
  3. If the WAL grows beyond a few hundred MB consistently, the write rate may be too high. Consider:
    • Reducing search logging verbosity
    • Raising the acceptable cache age (cache_max_age) to reduce repeated engine calls
    • Disabling server-side history for non-owner users
  4. The -shm file is a shared memory index for WAL and is safe to ignore.

Prevention: The server uses separate read and write DB connections. The write connection handles checkpointing. Under normal operation, WAL files stay small (<50 MB).

Peer auth failures

Symptoms: Friend instances show errors in logs, peer cache sharing fails, proxy requests return 401/403.

Diagnosis:

  1. Verify peer-secret in config.kdl matches on both sides.
  2. Check that the friend’s URL in peers.kdl is reachable and includes the correct protocol (https://).
  3. Look for TLS certificate errors in logs – self-signed certs need explicit trust.
  4. Verify the friend instance is running a compatible API version (/ami4got returns version info).

Common issues:

  • Clock skew: if timestamps are used in auth tokens, ensure NTP is synced on both instances.
  • Firewall rules: peer cache uses /api/v1/cache and /api/v1/proxy endpoints – ensure they are not blocked.
  • Permissions: a friend needs no group. It is known by peer-secret, and its push by its pubkey in peers.kdl.

Memory usage

Symptoms: The server process consumes more memory than expected, or OOM-kills occur.

Common causes:

  1. Image proxy cache: In-memory image cache grows with traffic. Configure max_cache_size in the image proxy config, or rely on SQLite-backed caching with eviction.
  2. Highlight regex cache: Capped at 10,000 entries, auto-evicts when full. Not usually a problem.
  3. Peer cache: Cached results from friend instances are held in memory. Large peer networks with high traffic multiply memory usage.
  4. AI research: The LLM research agent (if enabled) buffers responses. Each concurrent research session uses memory proportional to response length.
  5. Prerendered captchas: Image data is held in memory until served. The pool size is bounded.

Monitoring: Check /ami4got for basic stats. For detailed memory profiling, run with GODEBUG=gctrace=1 or attach pprof if built with the debug profile.

Mitigation:

  • Set GOGC environment variable to control GC aggressiveness (default 100; lower values like 50 trade CPU for less memory).
  • Reduce max_cache_size for image proxy.
  • Limit concurrent AI research sessions.

Common Docker issues

Symptoms: Container fails to start, database errors, or static files not found.

Template/static file not found:

  • The Dockerfile copies go-server/templates/ and static/ into the image. If you modified the directory structure, update the Dockerfile paths.
  • Verify with docker exec <container> ls /app/templates/ and ls /app/static/.

Database permissions:

  • SQLite needs write access to the data directory. Mount a volume: -v ./data:/app/data.
  • If the container runs as a non-root user, ensure the volume has correct ownership.

Port binding:

  • Default port is 8080. Map it with -p 8080:8080 or set HOST / PORT environment variables.
  • In docker-compose.yml, verify the ports section matches your config.

CGO / SQLite:

  • The binary requires CGO for SQLite. The Dockerfile uses CGO_ENABLED=1. If building a custom image, ensure gcc and sqlite-dev are installed.

Health checks:

  • Use /ami4got as a Docker health check endpoint: HEALTHCHECK CMD curl -sf http://localhost:8080/ami4got || exit 1.

fly.io specific:

  • The fly.toml mounts a persistent volume at /data. Ensure the volume exists: fly volumes create data.
  • Memory: fly.io shared-1x VMs have 256 MB. If using AI research or large peer networks, upgrade to at least 512 MB.