Skip to content

Commit 89ea75b

Browse files
committed
fix(discovery): enforce reader admission across workspace changes
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
1 parent 0cf2248 commit 89ea75b

4 files changed

Lines changed: 88 additions & 17 deletions

File tree

‎crates/openshell-server/src/grpc/service_discovery.rs‎

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,6 @@ mod tests {
755755
let error = watch(
756756
&state,
757757
authed_request(WatchServiceRoutesRequest {
758-
workspaces: Vec::new(),
759758
workspace_scope: request().workspace_scope,
760759
workspaces: Vec::new(),
761760
}),
@@ -999,7 +998,7 @@ mod tests {
999998
})
1000999
)
10011000
.await
1002-
.is_err()
1001+
.is_ok()
10031002
);
10041003
let mut outsider = authed_request(request());
10051004
if let Some(Principal::User(user)) = outsider.extensions_mut().get_mut::<Principal>() {
@@ -1836,7 +1835,7 @@ mod tests {
18361835
.unwrap();
18371836
}
18381837
assert_eq!(
1839-
selected_snapshot(&state, &principal, &Selection::All)
1838+
selected_snapshot(&state, &principal, &Selection::All, &[])
18401839
.await
18411840
.unwrap_err()
18421841
.code(),
@@ -1846,7 +1845,8 @@ mod tests {
18461845
selected_snapshot(
18471846
&state,
18481847
&principal,
1849-
&Selection::Named(vec!["default".into()])
1848+
&Selection::Named(vec!["default".into()]),
1849+
&["default".into()]
18501850
)
18511851
.await
18521852
.is_ok()
@@ -1921,9 +1921,14 @@ mod tests {
19211921
.await
19221922
.unwrap();
19231923
let selected = Selection::Named(vec!["default".into(), "team-b".into()]);
1924-
let both = selected_snapshot(&state, &principal, &selected)
1925-
.await
1926-
.unwrap();
1924+
let both = selected_snapshot(
1925+
&state,
1926+
&principal,
1927+
&selected,
1928+
&["default".into(), "team-b".into()],
1929+
)
1930+
.await
1931+
.unwrap();
19271932
assert_eq!(
19281933
both.routes
19291934
.iter()
@@ -1933,22 +1938,81 @@ mod tests {
19331938
);
19341939
assert_eq!(
19351940
both,
1936-
selected_snapshot(&state, &principal, &Selection::All)
1937-
.await
1938-
.unwrap()
1941+
selected_snapshot(
1942+
&state,
1943+
&principal,
1944+
&Selection::All,
1945+
&["default".into(), "team-b".into()]
1946+
)
1947+
.await
1948+
.unwrap()
19391949
);
19401950
state
19411951
.store
19421952
.delete("workspace", "workspace-b")
19431953
.await
19441954
.unwrap();
19451955
assert_eq!(
1946-
selected_snapshot(&state, &principal, &Selection::All)
1956+
selected_snapshot(&state, &principal, &Selection::All, &["default".into()])
19471957
.await
19481958
.unwrap()
19491959
.routes
19501960
.len(),
19511961
1
19521962
);
19531963
}
1964+
#[tokio::test]
1965+
async fn all_workspace_watch_admits_new_workspaces_before_publishing_their_routes() {
1966+
use openshell_core::proto::{ObjectMeta, Workspace};
1967+
let (state, principal, _dir) = reader_fixture(true).await;
1968+
let mut stream = watch(
1969+
&state,
1970+
reader_request(
1971+
WatchServiceRoutesRequest {
1972+
workspace_scope: Some(openshell_core::proto::all_workspaces_selector()),
1973+
workspaces: Vec::new(),
1974+
},
1975+
&principal,
1976+
),
1977+
)
1978+
.await
1979+
.unwrap()
1980+
.into_inner();
1981+
assert!(stream.next().await.unwrap().is_ok());
1982+
let blockers = (0..WATCHES_PER_WORKSPACE)
1983+
.map(|n| {
1984+
state
1985+
.discovery
1986+
.admit(&user(&format!("blocker-{n}")), &["later".into()], true)
1987+
.unwrap()
1988+
})
1989+
.collect::<Vec<_>>();
1990+
state
1991+
.store
1992+
.put_message(&Workspace {
1993+
metadata: Some(ObjectMeta {
1994+
id: "later".into(),
1995+
name: "later".into(),
1996+
..Default::default()
1997+
}),
1998+
..Default::default()
1999+
})
2000+
.await
2001+
.unwrap();
2002+
let error = tokio::time::timeout(Duration::from_secs(3), stream.next())
2003+
.await
2004+
.unwrap()
2005+
.unwrap()
2006+
.unwrap_err();
2007+
assert_eq!(error.code(), tonic::Code::ResourceExhausted);
2008+
assert!(stream.next().await.is_none());
2009+
assert_eq!(state.discovery_watches.available_permits(), 32);
2010+
drop(blockers);
2011+
assert!(
2012+
state
2013+
.discovery
2014+
.admit(&principal, &["default".into(), "later".into()], true)
2015+
.is_ok()
2016+
);
2017+
}
19542018
}

‎crates/openshell-server/src/multiplex.rs‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,11 @@ impl MultiplexService {
338338
self.state.gateway_interceptors.clone(),
339339
Some(self.state.clone()),
340340
);
341-
let discovery = ServiceDiscoveryServer::new(OpenShellService::new(self.state.clone()))
342-
.max_decoding_message_size(MAX_GRPC_DECODE_SIZE);
343-
let discovery = GatewayInterceptorGrpcService::new(
344-
discovery,
341+
let discovery_service =
342+
ServiceDiscoveryServer::new(OpenShellService::new(self.state.clone()))
343+
.max_decoding_message_size(MAX_GRPC_DECODE_SIZE);
344+
let discovery_service = GatewayInterceptorGrpcService::new(
345+
discovery_service,
345346
self.state.gateway_interceptors.clone(),
346347
Some(self.state.clone()),
347348
);
@@ -354,7 +355,7 @@ impl MultiplexService {
354355
let grpc_service = AuthGrpcRouter::with_peer_identity(
355356
GrpcRouter::new(openshell, reflection)
356357
.with_sandbox_updates(sandbox_updates)
357-
.with_discovery(discovery),
358+
.with_discovery(discovery_service),
358359
authenticator_chain,
359360
authz_policy,
360361
self.state

‎crates/openshell-server/src/storage_proto.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ mod tests {
179179
// updates use a separate capability/service and add one classified RPC.
180180
// Discovery RPCs move to ServiceDiscovery; message and durable closures are unchanged.
181181
const PUBLIC_RPC_SCHEMA_SHA256: &str =
182-
"9570c5a65c405284cecb1d14067f91be2ce5d5dc98f2ceb0d7504ded776a863c";
182+
"1c3bf59d4cd397c2b4428bdfeff951323de10bbda6c93622af842c3d025cd9be";
183183
const DURABLE_SCHEMA_SHA256: &str =
184184
"cb15f8f79a855064a43fe8c6cd908bf07eca6604e2bf8ab7d2de0ef33e97da4e";
185185
const PUBLIC_DURABLE_OVERLAP_SHA256: &str =

‎docs/how-it-works/gateways/configuration.mdx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,3 +2088,9 @@ For rotation, add the replacement fingerprint, project the new certificate/key
20882088
to the consumer, then remove the old fingerprint. The proxy reloads mounted
20892089
identity and trust files on reconnect. No certificate issuance or renewal is
20902090
performed by the gateway.
2091+
2092+
Finite and all-workspace watches reserve capacity for every selected active
2093+
workspace. When that set changes, the watch reacquires workspace capacity before
2094+
publishing the next view. A newly selected workspace at capacity returns
2095+
`RESOURCE_EXHAUSTED`; the client can reconnect. Installation-record limits apply
2096+
per workspace; route and response-size limits also apply to the combined view.

0 commit comments

Comments
 (0)