paragonie/random_compat · error · Exception
Error reading from source device
Error message
Error reading from source device
What it means
Sentinel failure of the random_compat polyfill's random_bytes() on the /dev/urandom backend: every read attempt from the entropy source failed or returned a buffer whose length did not match the requested $bytes count. It means the OS entropy device was unreadable or returned short/failed reads (e.g. /dev/urandom missing or restricted in a chroot/container), so no cryptographically secure entropy could be produced.
Solutions
- Verify /dev/urandom exists and is readable by the PHP process (check open_basedir, chroot, and container device mounts)
- Ensure the PHP build supports reading the device (ext/openssl or ext/mcrypt alternatives are tried before this throw; enabling them avoids the urandom path)
- Upgrade PHP to 7.0+ where native random_bytes() exists and bypasses the polyfill entirely
- Log the environment details and retry the operation; a transient read failure may succeed on a subsequent call
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at lib/random_bytes_dev_urandom.php:186 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of paragonie/random_compat@b5d188cc9d (2026-09-13).
Data as JSON: /api/errors/96b84598f95938ac.
Report an issue: GitHub.
Appendix: source
Thrown at lib/random_bytes_dev_urandom.php:186
/**
* Is our result valid?
* @var string|bool $buf
*/
if (is_string($buf)) {
if (RandomCompat_strlen($buf) === $bytes) {
/**
* Return our random entropy buffer here:
*/
return $buf;
}
}
}
/**
* If we reach here, PHP has failed us.
*/
throw new Exception(
'Error reading from source device'
);
}
}
View on GitHub (pinned to b5d188cc9d)