hyperledger/fabric · critical

error getting random bytes

Error message

error getting random bytes

What it means

getRandomNonce reads 24 cryptographically random bytes via crypto/rand; this error wraps any failure of rand.Read. It is a system-level failure (entropy source unavailable) surfaced whenever a nonce is created for a proposal or txid.

Source

Thrown at protoutil/commonutils.go:287

}

// EnvelopeToConfigUpdate is used to extract a ConfigUpdateEnvelope from an envelope of
// type CONFIG_UPDATE
func EnvelopeToConfigUpdate(configtx *cb.Envelope) (*cb.ConfigUpdateEnvelope, error) {
	configUpdateEnv := &cb.ConfigUpdateEnvelope{}
	_, err := UnmarshalEnvelopeOfType(configtx, cb.HeaderType_CONFIG_UPDATE, configUpdateEnv)
	if err != nil {
		return nil, err
	}
	return configUpdateEnv, nil
}

func getRandomNonce() ([]byte, error) {
	key := make([]byte, 24)

	_, err := rand.Read(key)
	if err != nil {
		return nil, errors.Wrap(err, "error getting random bytes")
	}
	return key, nil
}

func IsConfigTransaction(envelope *cb.Envelope) bool {
	payload, err := UnmarshalPayload(envelope.Payload)
	if err != nil {
		return false
	}

	if payload.Header == nil {
		return false
	}

	hdr, err := UnmarshalChannelHeader(payload.Header.ChannelHeader)
	if err != nil {
		return false
	}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Ensure /dev/urandom is accessible in the container/host and not blocked by seccomp or device cgroup rules
  2. Check kernel entropy health (dmesg for random: messages); add haveged/rngd only on legacy kernels
  3. Retry the operation — crypto/rand failures are usually transient or environmental
  4. If inside a custom sandbox, verify getrandom(2) syscall is permitted
Defensive patterns

Strategy: retry

Validate before calling

// No caller-side pre-check possible; verify entropy source availability instead:
// In deployment: test `head -c 24 /dev/urandom > /dev/null` works in the container.
if _, err := os.Stat("/dev/urandom"); err != nil {
	return fmt.Errorf("entropy source unavailable: %w", err)
}

Try / catch

nonce, err := protoutil.CreateNonce()
if err != nil {
	if strings.Contains(err.Error(), "random bytes") {
		// transient/environmental: back off and retry
		time.Sleep(backoff)
		nonce, err = protoutil.CreateNonce()
	}
	if err != nil { return fmt.Errorf("entropy failure, check /dev/urandom and seccomp profile: %w", err) }
}

Prevention

When it happens

Trigger: Indirectly triggered via CreateNonce, CreateChaincodeProposalWithTransient/WithTxIDAndTransient, or CreateProposalFromCISAndTxid when crypto/rand.Read fails — e.g. entropy pool exhausted, or running in a container/sandbox where /dev/urandom is unavailable or blocked.

Common situations: Containers with restricted /dev/urandom access; seccomp/AppArmor profiles blocking getrandom(2); extremely low-entropy environments (rare on modern Linux); VMs without a hardware RNG early in boot.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/a3d018f77a282a05. Report an issue: GitHub.