{"record":{"id":"fa2535b68035e37f","repo":"facebook/flow","slug":"failed-to-create-tokio-runtime-fa2535","errorCode":null,"errorMessage":"Failed to create tokio runtime","messagePattern":"Failed to create tokio runtime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"rust_port/crates/flow_server/src/server.rs","lineNumber":285,"sourceCode":") {\n    loop {\n        tokio::task::yield_now().await;\n        let done = orchestrator.collect_heap_slice(Arc::clone(&committed_heap), 10000);\n        if done {\n            break;\n        }\n    }\n}\n\nfn serve(\n    _genv: &Genv,\n    committed_heap: &Arc<flow_heap::heap_state::CommittedHeap>,\n    orchestrator: &server_orchestrator::ServerOrchestratorHandle,\n) {\n    let runtime = tokio::runtime::Builder::new_current_thread()\n        .enable_all()\n        .build()\n        .expect(\"Failed to create tokio runtime\");\n    loop {\n        monitor_rpc::status_update(server_status::Event::Ready);\n\n        let _options = &_genv.options;\n\n        let _start_time = std::time::SystemTime::now()\n            .duration_since(std::time::UNIX_EPOCH)\n            .unwrap_or_default()\n            .as_secs_f64();\n        runtime.block_on(async {\n            let orchestrator_for_gc = orchestrator.clone();\n            let idle_thread = async {\n                tokio::join!(\n                    idle_logging_loop(Arc::clone(_options), _start_time),\n                    gc_loop(Arc::clone(committed_heap), orchestrator_for_gc),\n                );\n            };\n            let process_updates = |skip_incompatible: bool, updates: &BTreeSet<String>| {","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_server/src/server.rs#L267-L303","documentation":"The Flow server's serve loop builds a single-threaded tokio runtime via Builder::new_current_thread().enable_all().build() and expects success (rust_port/crates/flow_server/src/server.rs:283-286). build() fails when tokio cannot set up its I/O and time drivers — practically when it cannot spawn the driver thread or register with epoll/kqueue due to OS resource limits. This expect aborts the whole server process at startup when the environment cannot host an async runtime.","triggerScenarios":"Server startup under OS limits: RLIMIT_NPROC or cgroup pids.max exhausted, RLIMIT_NOFILE too low for the driver's epoll fd, seccomp/sandboxes blocking epoll_create or clone, or memory pressure preventing the driver stack allocation. Custom builds of flow_server with tokio compiled without the required features (rt, net, time) fail the same way.","commonSituations":"Docker/Kubernetes containers with low pids or memory limits; CI sandboxes; many flow server instances per host; embedding flow_server with a trimmed tokio feature set.","solutions":["Raise the relevant limits (ulimit -u, ulimit -n, container pids.max and memory) and restart the server","Check dmesg or container events for OOM kills or thread-creation failures at the crash timestamp","If embedding, verify tokio features (rt, net, time, macros) and reuse an existing runtime instead of building a new one","Replace the expect with graceful error reporting so startup exits with a diagnostic status instead of a panic"],"exampleFix":"// before\nlet runtime = tokio::runtime::Builder::new_current_thread()\n    .enable_all()\n    .build()\n    .expect(\"Failed to create tokio runtime\");\n\n// after\nlet runtime = tokio::runtime::Builder::new_current_thread()\n    .enable_all()\n    .build()\n    .unwrap_or_else(|e| {\n        eprintln!(\"failed to init tokio runtime: {e}; check thread/fd/memory limits\");\n        std::process::exit(1);\n    });","handlingStrategy":"validation","validationCode":"// Probe async-runtime prerequisites before serving\nlet probe = tokio::runtime::Builder::new_current_thread().enable_all().build();\nif probe.is_err() {\n    eprintln!(\"cannot init tokio runtime; check ulimit -u/-n and memory limits\");\n    std::process::exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set adequate ulimit -n and pids limits in service units or container specs before deploying the server","Budget one driver thread plus its fds for the tokio runtime in capacity planning","When embedding, reuse an existing tokio Runtime rather than building a new one per serve call"],"tags":["tokio","runtime","server-startup","resource-limits","panic"],"backgroundTag":"tokio-runtime-build-failed","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}