Your NATS JetStream errors mean that the JetStream functionality, which provides persistence and advanced messaging features, is not properly configured or available to your NATS server. This typically manifests as clients being unable to publish or subscribe to streams or consumers, leading to errors like "jetstream not enabled" or "stream not found."

Common Causes and Fixes

  1. JetStream Not Explicitly Enabled in NATS Server Configuration

    • Diagnosis: Check your NATS server configuration file (usually nats-server.conf or similar). Look for a jetstream block. If it’s missing or commented out, JetStream is disabled.
    • Fix: Add or uncomment the jetstream block in your configuration file. For a basic setup, this looks like:
      jetstream: { }
      
      If you need persistent storage for JetStream, you’ll need to configure a store_dir:
      jetstream: {
        store_dir: "/var/lib/nats/jetstream"
      }
      
      Replace /var/lib/nats/jetstream with your desired persistent storage path. Ensure the NATS server process has write permissions to this directory.
    • Why it works: The NATS server binary has JetStream functionality built-in, but it’s an opt-in feature. This configuration explicitly tells the server to load and enable the JetStream components upon startup.
  2. Incorrect store_dir Permissions or Non-existent Directory

    • Diagnosis: If JetStream is enabled in the config but still failing, verify the directory specified in store_dir exists and that the user running the NATS server process has read/write permissions. Use ls -ld /var/lib/nats/jetstream and ps aux | grep nats-server to identify the user.
    • Fix: Create the directory if it doesn’t exist (sudo mkdir -p /var/lib/nats/jetstream) and set ownership/permissions. If NATS runs as user nats, use sudo chown nats:nats /var/lib/nats/jetstream and sudo chmod 755 /var/lib/nats/jetstream.
    • Why it works: JetStream requires a directory to store its metadata and message data. Without proper access, it cannot initialize its storage backend, preventing JetStream operations.
  3. Insufficient File System Limits (ulimit)

    • Diagnosis: JetStream can be file descriptor intensive, especially under high load or with many streams/consumers. Check the nofile (number of open files) limit for the NATS server process. Use cat /proc/<nats_pid>/limits or ulimit -n within the NATS server’s environment. The default limit (e.g., 1024) might be too low.
    • Fix: Increase the nofile limit in the system’s ulimit configuration (e.g., by editing /etc/security/limits.conf or systemd service files) to a higher value, such as 65536. For example, in /etc/security/limits.conf:
      nats          soft    nofile          65536
      nats          hard    nofile          65536
      
      Then, restart the NATS server.
    • Why it works: Each open file, network connection, and internal NATS object consumes a file descriptor. A low limit can cause the server to fail to open necessary files for JetStream’s operation or to gracefully handle new connections.
  4. NATS Server Version Incompatibility or Missing JetStream Binary

    • Diagnosis: JetStream was introduced in NATS server version 2.0.0. Older versions will not support it. Verify your NATS server version with nats-server --version.
    • Fix: Upgrade your NATS server to a version that supports JetStream (2.0.0 or later). Download the latest binary from the official NATS releases page on GitHub.
    • Why it works: JetStream is a feature of the NATS server binary itself. If you’re running an older version, the code for JetStream simply doesn’t exist, and enabling it in the configuration will have no effect.
  5. Cluster Configuration Issues (if applicable)

    • Diagnosis: In a clustered NATS setup, JetStream state needs to be properly replicated. Errors might indicate nodes not forming a cluster correctly or JetStream not being enabled on all nodes intended to host JetStream state. Check cluster status and logs on all nodes.
    • Fix: Ensure all nodes in the cluster are running compatible NATS server versions, have their jetstream: { } configuration enabled, and are correctly configured to peer with each other. Verify network connectivity between cluster nodes on the NATS port (default 4222) and the cluster port (default 6222).
    • Why it works: JetStream relies on the underlying NATS cluster for fault tolerance and state synchronization. If the cluster itself is unhealthy, or if JetStream is only partially enabled across nodes, it cannot function reliably.
  6. Resource Exhaustion (Memory/CPU/Disk I/O)

    • Diagnosis: While not a direct "JetStream not enabled" error, severe resource constraints can cause JetStream components to crash or become unresponsive, leading to client-side errors that look like JetStream is disabled. Monitor system resources (top, htop, iostat, dmesg).
    • Fix: Allocate more resources (CPU, RAM) to the NATS server host, optimize NATS configuration for expected load, or reduce the load from clients. Ensure the disk where store_dir resides has sufficient free space and is not experiencing excessive I/O wait.
    • Why it works: JetStream needs system resources to operate. If the server is starved, critical background processes for JetStream can fail, leading to instability and perceived unavailability.

After ensuring JetStream is enabled and correctly configured, the next error you’ll likely encounter if you haven’t created any streams yet is a "stream not found" error when attempting to publish or subscribe.

Want structured learning?

Take the full Nats course →