The NATS JetStream component responsible for managing stream metadata failed to find the requested stream, indicating a critical discrepancy between what the client asked for and what the server believed existed.

This error, nats: stream not found (or its underlying 404 Not Found HTTP status), typically arises when a client attempts to publish to or consume from a JetStream stream that either doesn’t exist, has been deleted, or its metadata has become corrupted or inaccessible. The most common culprits involve lifecycle issues, configuration mismatches, or underlying storage problems.

1. Stream Never Created or Incorrectly Named

  • Diagnosis: Check the NATS server’s logs for stream creation events. Use the nats CLI to list existing streams:
    nats stream ls
    
  • Fix: Ensure the stream was created with the exact name the client is trying to use. If not, create it:
    nats stream add my-stream --subjects "my.subject" --ack policy=all --retention limits --max-msgs 1000 --max-bytes 1GB
    
    This command creates my-stream for subjects matching my.subject, requires all publishers to receive acknowledgments, retains messages based on limits, and sets limits on message count and size. The stream is now explicitly defined and discoverable.

2. Client Using Wrong Stream Name or Context

  • Diagnosis: Verify the stream name specified in your client application’s configuration or code against the output of nats stream ls. Pay close attention to case sensitivity and leading/trailing spaces.
  • Fix: Correct the stream name in your client code or configuration to match the one that exists on the server. For example, if the stream is events but your client is looking for Events, update the client configuration to use events. This aligns the client’s request with the server’s known streams.

3. Stream Deleted or Purged

  • Diagnosis: Examine NATS server logs for stream deleted or stream purged messages related to the expected stream name.
  • Fix: Recreate the stream using the nats stream add command as described in cause #1. If the data is important, you may need to re-publish messages from a backup or a different source. Recreating the stream re-establishes its presence in the JetStream metadata.

4. JetStream Storage Backend Issues (File System or Object Storage)

  • Diagnosis:
    • File System: Check the NATS server logs for I/O errors or permission denied messages related to the JetStream data directory. Verify disk space (df -h).
    • Object Storage: Check cloud provider logs for errors related to bucket access, permissions, or throttling. Verify credentials and network connectivity.
  • Fix:
    • File System: Resolve underlying disk issues, ensure sufficient disk space, and verify NATS process has read/write permissions to the data directory (e.g., chown nats:nats /var/lib/nats/jetstream). This allows JetStream to read and write stream metadata and message data.
    • Object Storage: Correct IAM policies, API keys, or network configurations. Ensure the NATS service account has the necessary permissions (e.g., s3:PutObject, s3:GetObject, s3:DeleteObject) for the target bucket. This restores NATS’s ability to interact with its persistent storage.

5. NATS Server Restarted Without Persistent Metadata

  • Diagnosis: If JetStream was configured with store_dir pointing to a non-persistent location (like /tmp), or if the underlying storage was lost, JetStream’s metadata would be lost on restart. Check server logs for messages indicating JetStream initialization and metadata loading.
  • Fix: Configure store_dir to a persistent location (e.g., /var/lib/nats/jetstream) in your NATS server configuration file and restart the server. Ensure the directory exists and has correct permissions. This ensures JetStream’s state is preserved across restarts.

6. Cluster Synchronization Issues (Less Common)

  • Diagnosis: In a clustered NATS setup, if a stream was created on one node but cluster gossip or Raft consensus failed to propagate it to the node the client is connected to, this error can occur. Check NATS server logs on all cluster members for errors related to cluster communication or Raft.
  • Fix: Restart the NATS nodes that are experiencing communication issues. Ensure the cluster is healthy and all nodes can communicate. This allows the stream metadata to be replicated across all members of the JetStream cluster.

7. Corrupted JetStream Metadata

  • Diagnosis: This is a rare but serious issue. Look for highly unusual errors in NATS server logs, potentially including stack traces related to data deserialization or file corruption.
  • Fix: The most reliable fix is often to remove the corrupted stream’s data from the store_dir (or object storage) and re-create the stream. This requires identifying the specific files or objects associated with the stream. If you can’t identify them, you may need to stop NATS, clear the store_dir, and restart NATS. This forces JetStream to rebuild its metadata from scratch, but all previously stored messages will be lost.

After resolving these, the next error you’ll likely encounter, if you haven’t addressed it already, is nats: subject not found if the stream’s subjects are not correctly configured to match the messages being published or consumed.

Want structured learning?

Take the full Nats course →