nats-io/nats-server · error

could not create hash: %v

Error message

could not create hash: %v

What it means

The file store initializes a HighwayHash digest for message block checksums using highwayhash.NewDigest64 with a SHA-256 key derived from the stream name. If that construction fails, the error is wrapped. This is rare and generally indicates a library/dependency problem rather than user misconfiguration.

Source

Thrown at server/filestore.go:498

	// Set flush in place to AsyncFlush which by default is false.
	fs.fip = !fcfg.AsyncFlush

	// Check if this is a new setup.
	mdir := filepath.Join(fcfg.StoreDir, msgDir)
	odir := filepath.Join(fcfg.StoreDir, consumerDir)
	if err := os.MkdirAll(mdir, defaultDirPerms); err != nil {
		return nil, fmt.Errorf("could not create message storage directory - %v", err)
	}
	if err := os.MkdirAll(odir, defaultDirPerms); err != nil {
		return nil, fmt.Errorf("could not create consumer storage directory - %v", err)
	}

	// Create highway hash for message blocks. Use sha256 of directory as key.
	key := sha256.Sum256([]byte(cfg.Name))
	fs.hh, err = highwayhash.NewDigest64(key[:])
	if err != nil {
		return nil, fmt.Errorf("could not create hash: %v", err)
	}

	keyFile := filepath.Join(fs.fcfg.StoreDir, JetStreamMetaFileKey)
	_, err = os.Stat(keyFile)
	// Either the file should exist (err=nil), or it shouldn't. Any other error is reported.
	if err != nil && !os.IsNotExist(err) {
		return nil, err
	}
	// Make sure we do not have an encrypted store underneath of us but no main key.
	if fs.prf == nil && err == nil {
		return nil, errNoMainKey
	} else if fs.prf != nil && err == nil {
		// If encryption is configured and the key file exists, recover our keys.
		if err = fs.recoverAEK(); err != nil {
			return nil, err
		}
	}

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Rebuild/re-vendor dependencies (go mod tidy && go mod vendor) to get an intact highwayhash package
  2. Update to a current NATS server version where the dependency is known-good
  3. Report upstream with the wrapped error if it persists on supported platforms
Defensive patterns

Strategy: try-catch

Try / catch

fs, err := newFileStoreWithCreatedAndMode(fcfg, cfg, now, prf, oldprf, false)
if err != nil {
    if strings.Contains(err.Error(), "could not create hash") {
        return fmt.Errorf("environment/dependency issue: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: highwayhash.NewDigest64(key[:]) returns an error during file store creation (server/filestore.go:498).

Common situations: Corrupted or incompatible golang.org/x/crypto/highwayhash dependency/build; platform lacking the required SIMD/assembly support for the package.

Related errors


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/77e0872de311a98b. Report an issue: GitHub.