|
1 | 1 | use super::{discover, AllowPolicy, CheckPolicy, DefaultPolicy, DeniedUnknownPort}; |
2 | | -use futures::prelude::*; |
3 | 2 | use linkerd_app_core::{proxy::http, transport::OrigDstAddr, Error, Result}; |
4 | 3 | pub use linkerd_server_policy::{Authentication, Authorization, Protocol, ServerPolicy, Suffix}; |
5 | 4 | use std::{ |
6 | 5 | collections::{HashMap, HashSet}, |
7 | | - future::Future, |
8 | 6 | hash::{BuildHasherDefault, Hasher}, |
9 | 7 | sync::Arc, |
10 | 8 | }; |
11 | 9 | use tokio::sync::watch; |
12 | | -use tracing::{info_span, Instrument}; |
| 10 | +use tracing::info_span; |
13 | 11 |
|
14 | 12 | #[derive(Clone, Debug)] |
15 | 13 | pub struct Store { |
@@ -74,49 +72,41 @@ impl Store { |
74 | 72 | /// provided ports. The store maintains these watches so that each time a policy is checked, it |
75 | 73 | /// may obtain the latest policy provided by the watch. An error is returned if any of the |
76 | 74 | /// watches cannot be established. |
77 | | - // |
78 | | - // XXX(ver): rustc can't seem to figure out that this Future is `Send` unless we annotate it |
79 | | - // explicitly, hence the manual_async_fn. |
80 | | - #[allow(clippy::manual_async_fn)] |
81 | 75 | pub(super) fn spawn_discover<S>( |
82 | 76 | default: DefaultPolicy, |
83 | 77 | ports: HashSet<u16>, |
84 | 78 | discover: discover::Watch<S>, |
85 | | - ) -> impl Future<Output = Result<Self>> + Send |
| 79 | + ) -> Self |
86 | 80 | where |
87 | 81 | S: tonic::client::GrpcService<tonic::body::BoxBody, Error = Error>, |
88 | 82 | S: Clone + Send + Sync + 'static, |
89 | 83 | S::Future: Send, |
90 | 84 | S::ResponseBody: http::HttpBody<Error = Error> + Send + Sync + 'static, |
91 | 85 | { |
92 | | - async move { |
93 | | - let rxs = ports.into_iter().map(|port| { |
94 | | - discover |
95 | | - .clone() |
96 | | - .spawn_watch(port) |
97 | | - .instrument(info_span!("watch", %port)) |
98 | | - .map_ok(move |rsp| (port, rsp.into_inner())) |
99 | | - }); |
100 | | - |
101 | | - let ports = futures::future::join_all(rxs) |
102 | | - .await |
103 | | - .into_iter() |
104 | | - .collect::<Result<PortMap<_>, tonic::Status>>()?; |
105 | | - |
106 | | - let default = match Self::mk_default(default) { |
107 | | - Some((tx, rx)) => { |
108 | | - tokio::spawn(async move { |
109 | | - tx.closed().await; |
110 | | - }); |
111 | | - Some(rx) |
112 | | - } |
113 | | - None => None, |
114 | | - }; |
115 | | - |
116 | | - Ok(Self { |
117 | | - default, |
118 | | - ports: Arc::new(ports), |
| 86 | + let rxs = ports |
| 87 | + .into_iter() |
| 88 | + .map(|port| { |
| 89 | + let discover = discover.clone(); |
| 90 | + let default = default.clone(); |
| 91 | + let rx = info_span!("watch", %port) |
| 92 | + .in_scope(|| discover.spawn_with_init(port, default.into())); |
| 93 | + (port, rx) |
119 | 94 | }) |
| 95 | + .collect::<PortMap<_>>(); |
| 96 | + |
| 97 | + let default = match Self::mk_default(default) { |
| 98 | + Some((tx, rx)) => { |
| 99 | + tokio::spawn(async move { |
| 100 | + tx.closed().await; |
| 101 | + }); |
| 102 | + Some(rx) |
| 103 | + } |
| 104 | + None => None, |
| 105 | + }; |
| 106 | + |
| 107 | + Self { |
| 108 | + default, |
| 109 | + ports: Arc::new(rxs), |
120 | 110 | } |
121 | 111 | } |
122 | 112 | } |
|
0 commit comments