shadowsocks/shadowsocks-rust · error
failed to encode DNS response
Error message
failed to encode DNS response
What it means
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.
Source
Thrown at crates/shadowsocks-service/src/local/fake_dns/udp_server.rs:80
error!("failed to parse DNS request, error: {}", err);
continue;
}
};
let rsp_message = match handle_dns_request(&req_message, &self.manager).await {
Ok(m) => m,
Err(err) => {
error!("failed to handle DNS request, error: {}", err);
Message::error_msg(req_message.id, req_message.op_code, ResponseCode::ServFail)
}
};
let rsp_buffer = match rsp_message.to_vec() {
Ok(b) => b,
Err(err) => {
error!("failed to encode DNS response, error: {}", err);
return Err(io::Error::new(io::ErrorKind::Other, err));
}
};
let _ = self.listener.send_to(&rsp_buffer, peer_addr).await;
}
}
}
View on GitHub (pinned to 8eb0f0a65b)
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
Defensive patterns
Strategy: try-catch
Try / catch
// client sees no UDP reply; guard with timeout and fallback:
match timeout(UDP_DNS_TIMEOUT, udp_dns_query(q)).await {
Ok(Err(_)) | Err(_) => fallback_to_system_resolver(q).await,
Ok(Ok(m)) => m,
} Prevention
- 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)
When it happens
Trigger: run() handles an inbound UDP DNS packet, builds rsp_message (typically an address-mapping answer), and Message::to_vec() returns a hickory encoding error.
Common situations: Oversized or unusual response failing to serialize; hickory-proto version incompatibility; corrupted/edge-case query triggering an invalid response construction.
Related errors
- failed to encode DNS response
- unexpected response from 8.8.8.8:53
- redir destination must not be an domain name address
- tun destination must not be an domain name address
- missing `local_dns_addr` or `remote_dns_addr` in configurati
AI-assisted analysis of shadowsocks/shadowsocks-rust@8eb0f0a65b (2026-09-09).
Data as JSON: /api/errors/3a341db97c4f1403.
Report an issue: GitHub.