{"record":{"id":"3a341db97c4f1403","repo":"shadowsocks/shadowsocks-rust","slug":"failed-to-encode-dns-response-3a341d","errorCode":null,"errorMessage":"failed to encode DNS response","messagePattern":"failed to encode DNS response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/shadowsocks-service/src/local/fake_dns/udp_server.rs","lineNumber":80,"sourceCode":"                    error!(\"failed to parse DNS request, error: {}\", err);\n                    continue;\n                }\n            };\n\n            let rsp_message = match handle_dns_request(&req_message, &self.manager).await {\n                Ok(m) => m,\n                Err(err) => {\n                    error!(\"failed to handle DNS request, error: {}\", err);\n\n                    Message::error_msg(req_message.id, req_message.op_code, ResponseCode::ServFail)\n                }\n            };\n\n            let rsp_buffer = match rsp_message.to_vec() {\n                Ok(b) => b,\n                Err(err) => {\n                    error!(\"failed to encode DNS response, error: {}\", err);\n                    return Err(io::Error::new(io::ErrorKind::Other, err));\n                }\n            };\n            let _ = self.listener.send_to(&rsp_buffer, peer_addr).await;\n        }\n    }\n}\n","sourceCodeStart":62,"sourceCodeEnd":87,"githubUrl":"https://github.com/shadowsocks/shadowsocks-rust/blob/8eb0f0a65b1d976ab6bed5787327ef86529b0435/crates/shadowsocks-service/src/local/fake_dns/udp_server.rs#L62-L87","documentation":"In the fake-DNS UDP server's run loop, converting the constructed response Message to wire bytes via rsp_message.to_vec() fails; the error is logged as \"failed to encode DNS response\" and returned as an io::Error. The UDP client receives no reply.","triggerScenarios":"run() handles an inbound UDP DNS packet, builds rsp_message (typically an address-mapping answer), and Message::to_vec() returns a hickory encoding error.","commonSituations":"Oversized or unusual response failing to serialize; hickory-proto version incompatibility; corrupted/edge-case query triggering an invalid response construction.","solutions":["Upgrade shadowsocks-service/hickory-proto to matching versions","Log and inspect the underlying encoder error and the offending query","Verify the fake-dns address mapping state isn't producing invalid record data","Work around by using real DNS resolution for the affected client"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// client sees no UDP reply; guard with timeout and fallback:\nmatch timeout(UDP_DNS_TIMEOUT, udp_dns_query(q)).await {\n    Ok(Err(_)) | Err(_) => fallback_to_system_resolver(q).await,\n    Ok(Ok(m)) => m,\n}","preventionTips":["Match hickory-proto versions across your dependency tree","Keep fake-dns mapping state bounded and valid","Retry UDP queries once before giving up (UDP is lossy)"],"tags":["dns","encoding","fake-dns","udp","serialization"],"backgroundTag":"dns-response-encode-failed","analyzedSha":"8eb0f0a65b1d976ab6bed5787327ef86529b0435","analyzedAt":"2026-09-09T12:20:43.168Z","contentChangedAt":"2026-09-09T12:20:43.168Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}