Bug 1601992 - Set write timeout on udp socket; r=ng
authorDan Minor <dminor@mozilla.com>
Wed, 11 Dec 2019 12:20:36 +0000
changeset 506471 a336ad33f55374536c61865e1a04ae022e0ef8b2
parent 506470 cdf525897bffc445c4c860225ecb42eda5925a86
child 506472 9e8a7f29d4ae654fa9853387a1ae8ebacb16ef09
push id36904
push userncsoregi@mozilla.com
push dateWed, 11 Dec 2019 17:42:45 +0000
treeherdermozilla-central@b823b005f00e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersng
bugs1601992
milestone73.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
media/mtransport/mdns_service/src/lib.rs
--- a/media/mtransport/mdns_service/src/lib.rs
+++ b/media/mtransport/mdns_service/src/lib.rs
@@ -258,16 +258,17 @@ impl MDNSService {
         socket.bind(&socket2::SockAddr::from(std::net::SocketAddr::from((
             [0, 0, 0, 0],
             port,
         ))))?;
 
         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!(
                     "Could not join multicast group on interface: {:?}: {}",
                     addr, err
                 );
             }
         }
@@ -322,17 +323,17 @@ impl MDNSService {
                         ServiceControl::Stop => {
                             trace!("Stopping");
                             break;
                         }
                     },
                     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();
                     while queries.len() < 5 && !unsent_queries.is_empty() {
                         if let Some(query) = unsent_queries.pop_front() {
                             if !pending_queries.contains_key(&query.hostname) {
                                 queries.push(query);
                             }
@@ -364,17 +365,17 @@ impl MDNSService {
                 let expired: Vec<String> = pending_queries
                     .iter()
                     .filter(|(_, query)| now.duration_since(query.timestamp).as_secs() >= 3)
                     .map(|(hostname, _)| hostname.to_string())
                     .collect();
                 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 {
                             hostname_timedout(&query.callback, &hostname);
                         }
                     }
                 }
 
@@ -650,16 +651,19 @@ mod tests {
             .unwrap();
 
         let socket = socket.into_udp_socket();
         socket.set_multicast_loop_v4(true).unwrap();
         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();
 
         let mut buffer: [u8; 1024] = [0; 1024];
         thread::spawn(move || {
             let start = time::Instant::now();
             let mut questions = Vec::new();
             while time::Instant::now().duration_since(start).as_secs() < stop {