{"record":{"id":"66b6d1bcfca9ccef","repo":"EpicGames/lore","slug":"failed-socket-setup","errorCode":null,"errorMessage":"Failed socket setup","messagePattern":"Failed socket setup","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lore-server/src/quic/stream_handler.rs","lineNumber":871,"sourceCode":"    /// Read one response header.\n    async fn response(recv: &mut RecvStream) -> CommandHeader {\n        let mut buffer = [0u8; 8];\n        recv.read_exact(&mut buffer)\n            .await\n            .expect(\"Failed to read response\");\n        CommandHeader::from_bytes(&buffer)\n    }\n\n    /// Serve `factory` for `protocol` on a loopback endpoint and open a client stream to it.\n    ///\n    /// The client skips certificate verification and presents none of its own; the mTLS tests\n    /// build their endpoints by hand because varying exactly that is what they test.\n    async fn serve_and_connect(\n        factory: Box<dyn StreamHandlerFactory>,\n        protocol: &'static str,\n    ) -> Harness {\n        let socket = UdpSocket::bind(\"127.0.0.1:0\").unwrap();\n        let server_addr = socket.local_addr().expect(\"Failed socket setup\");\n        drop(socket);\n\n        let (cert_path, key_path, _) = server_certs().expect(\"Bad cert paths\");\n        let server = QuinnServer::start(\n            QuinnConfigBuilder::new()\n                .address(server_addr)\n                .cert_file(cert_path)\n                .pkey_file(key_path)\n                .stream_handler_factory(factory)\n                .build()\n                .unwrap(),\n        )\n        .expect(\"Failed Quinn server start\");\n\n        let mut crypto_config = rustls::ClientConfig::builder()\n            .dangerous()\n            .with_custom_certificate_verifier(insecure_client_auth::SkipServerVerification::new())\n            .with_no_client_auth();","sourceCodeStart":853,"sourceCodeEnd":889,"githubUrl":"https://github.com/EpicGames/lore/blob/074eb0b0d1194c997d7cf28b55519e3e197b3e23/lore-server/src/quic/stream_handler.rs#L853-L889","documentation":"serve_and_connect() binds an ephemeral UDP socket on 127.0.0.1:0 and then calls local_addr() to learn the chosen port before dropping the socket; this expect panics if local_addr() errors. It only fails if the OS reports the socket invalid, i.e. the bind or socket state is broken.","triggerScenarios":"UdpSocket::bind succeeded but the fd was somehow closed/invalid by the time local_addr() runs (double-drop, fd exhaustion, sandboxed environment blocking getsockname).","commonSituations":"Running tests in restricted containers/sandboxes where socket metadata calls fail; file-descriptor exhaustion in large parallel test suites; rare OS-level socket errors.","solutions":["Retry the ephemeral bind if local_addr fails (transient OS issue)","Check fd limits (ulimit -n) when running many tests in parallel","Run outside sandboxed/privileged-restricted environments to rule out getsockname blocking","If intermittent, restructure to keep the socket open and pass it to Quinn instead of bind/drop"],"exampleFix":"// before\nlet socket = UdpSocket::bind(\"127.0.0.1:0\").unwrap();\nlet server_addr = socket.local_addr().expect(\"Failed socket setup\");\n// after\nlet socket = UdpSocket::bind(\"127.0.0.1:0\").expect(\"bind failed\");\nlet server_addr = socket.local_addr().expect(\"local_addr after successful bind failed\");","handlingStrategy":"validation","validationCode":"let socket = std::net::UdpSocket::bind(\"127.0.0.1:0\").expect(\"ephemeral bind failed\");\nlet server_addr = socket.local_addr().expect(\"local_addr failed\");\nassert!(server_addr.port() > 0);","typeGuard":"fn bound_addr(s: &std::net::UdpSocket) -> Option<std::net::SocketAddr> { s.local_addr().ok() }","tryCatchPattern":null,"preventionTips":["Prefer keeping the bound socket open and passing it to the QUIC stack instead of bind/drop","Raise fd limits for large parallel test runs","Avoid running tests in sandboxes that block getsockname"],"tags":["network","udp","test-harness","rust"],"backgroundTag":"socket-setup-failed","analyzedSha":"074eb0b0d1194c997d7cf28b55519e3e197b3e23","analyzedAt":"2026-09-13T09:00:57.509Z","contentChangedAt":"2026-09-13T09:00:57.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}