{"record":{"id":"c3d11c1966d62788","repo":"tauri-apps/tauri","slug":"failed-to-get-random-bytes-c3d11c","errorCode":null,"errorMessage":"failed to get random bytes","messagePattern":"failed to get random bytes","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/tauri/src/resources/mod.rs","lineNumber":83,"sourceCode":"\n/// Map-like data structure storing Tauri's resources (equivalent to file\n/// descriptors).\n///\n/// Provides basic methods for element access. A resource can be of any type.\n/// Different types of resources can be stored in the same map, and provided\n/// with a name for description.\n///\n/// Each resource is identified through a _resource ID (rid)_, which acts as\n/// the key in the map.\n#[derive(Default)]\npub struct ResourceTable {\n  index: BTreeMap<ResourceId, Arc<dyn Resource>>,\n}\n\nimpl ResourceTable {\n  fn new_random_rid() -> u32 {\n    let mut bytes = [0_u8; 4];\n    getrandom::fill(&mut bytes).expect(\"failed to get random bytes\");\n    u32::from_ne_bytes(bytes)\n  }\n\n  /// Inserts resource into the resource table, which takes ownership of it.\n  ///\n  /// The resource type is erased at runtime and must be statically known\n  /// when retrieving it through `get()`.\n  ///\n  /// Returns a unique resource ID, which acts as a key for this resource.\n  pub fn add<T: Resource>(&mut self, resource: T) -> ResourceId {\n    self.add_arc(Arc::new(resource))\n  }\n\n  /// Inserts a `Arc`-wrapped resource into the resource table.\n  ///\n  /// The resource type is erased at runtime and must be statically known\n  /// when retrieving it through `get()`.\n  ///","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/tauri-apps/tauri/blob/52e4b6e71d8632a7e648f866c442e287ecddee34/crates/tauri/src/resources/mod.rs#L65-L101","documentation":"ResourceTable assigns each resource a random 32-bit id (rid) via getrandom::fill() when a resource is added. The expect fires when the OS entropy source fails: getrandom(2)/ /dev/urandom unavailable in the execution environment.","triggerScenarios":"Adding any resource to the resource table (e.g. fs/http plugin resources) in a sandbox that blocks the getrandom syscall or /dev/urandom, or on minimal embedded systems.","commonSituations":"Restrictive seccomp/gVisor container profiles; custom minimal Linux images. Essentially never on normal desktop OSes.","solutions":["Allow the getrandom(2) syscall and /dev/urandom in the sandbox profile.","Use a standard base image or newer kernel.","Entropy access is mandatory for ResourceTable ids; no app-level workaround."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let mut probe = [0u8; 4];\nif getrandom::fill(&mut probe).is_err() {\n    return Err(\"OS entropy unavailable - resource ids cannot be generated\".into());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep getrandom(2) and /dev/urandom accessible in the runtime environment.","Smoke-test resource creation inside the deployment sandbox."],"tags":["tauri","resources","getrandom","sandbox","entropy"],"backgroundTag":"os-entropy-unavailable","analyzedSha":"52e4b6e71d8632a7e648f866c442e287ecddee34","analyzedAt":"2026-08-20T13:59:20.734Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}