Bug 1601992 - Set write timeout on udp socket; r=ng

We don't currently set a write timeout on the udp socket which could cause
write calls to block indefinitely. It is possible that this is blocking
long enough to cause the shutdown hangs seen in Bug 1601992.

This also bumps the number of times we retry failed queries from 2 to 3 to
account for the increased likelihood of not sending a query or answer.

Differential Revision: https://phabricator.services.mozilla.com/D56536

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dan Minor 2019-12-11 12:20:36 +00:00
Родитель e1fcfedadb
Коммит 2eadd0b6f8
1 изменённых файлов: 6 добавлений и 2 удалений

Просмотреть файл

@ -263,6 +263,7 @@ impl MDNSService {
let socket = socket.into_udp_socket();
socket.set_multicast_loop_v4(true)?;
socket.set_read_timeout(Some(time::Duration::from_millis(10)))?;
socket.set_write_timeout(Some(time::Duration::from_millis(10)))?;
for addr in addrs {
if let Err(err) = socket.join_multicast_v4(&mdns_addr, &addr) {
warn!(
@ -327,7 +328,7 @@ impl MDNSService {
Err(std::sync::mpsc::RecvTimeoutError::Disconnected) => {
break;
}
_ => {}
Err(std::sync::mpsc::RecvTimeoutError::Timeout) => {}
}
if pending_queries.len() < 50 {
let mut queries: Vec<Query> = Vec::new();
@ -369,7 +370,7 @@ impl MDNSService {
for hostname in expired {
if let Some(mut query) = pending_queries.remove(&hostname) {
query.attempts += 1;
if query.attempts < 2 {
if query.attempts < 3 {
query.timestamp = now;
unsent_queries.push_back(query);
} else {
@ -654,6 +655,9 @@ mod tests {
socket
.set_read_timeout(Some(time::Duration::from_millis(10)))
.unwrap();
socket
.set_write_timeout(Some(time::Duration::from_millis(10)))
.unwrap();
socket
.join_multicast_v4(&std::net::Ipv4Addr::new(224, 0, 0, 251), &addr)
.unwrap();