Skip to content

Commit 8df72ee

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

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
@@ -829,7 +829,6 @@ mod tests {
829829
let error = watch(
830830
&state,
831831
authed_request(WatchServiceRoutesRequest {
832-
workspaces: Vec::new(),
833832
workspace_scope: request().workspace_scope,
834833
workspaces: Vec::new(),
835834
}),
@@ -1073,7 +1072,7 @@ mod tests {
10731072
})
10741073
)
10751074
.await
1076-
.is_err()
1075+
.is_ok()
10771076
);
10781077
let mut outsider = authed_request(request());
10791078
if let Some(Principal::User(user)) = outsider.extensions_mut().get_mut::<Principal>() {
@@ -1910,7 +1909,7 @@ mod tests {
19101909
.unwrap();
19111910
}
19121911
assert_eq!(
1913-
selected_snapshot(&state, &principal, &Selection::All)
1912+
selected_snapshot(&state, &principal, &Selection::All, &[])
19141913
.await
19151914
.unwrap_err()
19161915
.code(),
@@ -1920,7 +1919,8 @@ mod tests {
19201919
selected_snapshot(
19211920
&state,
19221921
&principal,
1923-
&Selection::Named(vec!["default".into()])
1922+
&Selection::Named(vec!["default".into()]),
1923+
&["default".into()]
19241924
)
19251925
.await
19261926
.is_ok()
@@ -1995,9 +1995,14 @@ mod tests {
19951995
.await
19961996
.unwrap();
19971997
let selected = Selection::Named(vec!["default".into(), "team-b".into()]);
1998-
let both = selected_snapshot(&state, &principal, &selected)
1999-
.await
2000-
.unwrap();
1998+
let both = selected_snapshot(
1999+
&state,
2000+
&principal,
2001+
&selected,
2002+
&["default".into(), "team-b".into()],
2003+
)
2004+
.await
2005+
.unwrap();
20012006
assert_eq!(
20022007
both.routes
20032008
.iter()
@@ -2007,22 +2012,81 @@ mod tests {
20072012
);
20082013
assert_eq!(
20092014
both,
2010-
selected_snapshot(&state, &principal, &Selection::All)
2011-
.await
2012-
.unwrap()
2015+
selected_snapshot(
2016+
&state,
2017+
&principal,
2018+
&Selection::All,
2019+
&["default".into(), "team-b".into()]
2020+
)
2021+
.await
2022+
.unwrap()
20132023
);
20142024
state
20152025
.store
20162026
.delete("workspace", "workspace-b")
20172027
.await
20182028
.unwrap();
20192029
assert_eq!(
2020-
selected_snapshot(&state, &principal, &Selection::All)
2030+
selected_snapshot(&state, &principal, &Selection::All, &["default".into()])
20212031
.await
20222032
.unwrap()
20232033
.routes
20242034
.len(),
20252035
1
20262036
);
20272037
}
2038+
#[tokio::test]
2039+
async fn all_workspace_watch_admits_new_workspaces_before_publishing_their_routes() {
2040+
use openshell_core::proto::{ObjectMeta, Workspace};
2041+
let (state, principal, _dir) = reader_fixture(true).await;
2042+
let mut stream = watch(
2043+
&state,
2044+
reader_request(
2045+
WatchServiceRoutesRequest {
2046+
workspace_scope: Some(openshell_core::proto::all_workspaces_selector()),
2047+
workspaces: Vec::new(),
2048+
},
2049+
&principal,
2050+
),
2051+
)
2052+
.await
2053+
.unwrap()
2054+
.into_inner();
2055+
assert!(stream.next().await.unwrap().is_ok());
2056+
let blockers = (0..WATCHES_PER_WORKSPACE)
2057+
.map(|n| {
2058+
state
2059+
.discovery
2060+
.admit(&user(&format!("blocker-{n}")), &["later".into()], true)
2061+
.unwrap()
2062+
})
2063+
.collect::<Vec<_>>();
2064+
state
2065+
.store
2066+
.put_message(&Workspace {
2067+
metadata: Some(ObjectMeta {
2068+
id: "later".into(),
2069+
name: "later".into(),
2070+
..Default::default()
2071+
}),
2072+
..Default::default()
2073+
})
2074+
.await
2075+
.unwrap();
2076+
let error = tokio::time::timeout(Duration::from_secs(3), stream.next())
2077+
.await
2078+
.unwrap()
2079+
.unwrap()
2080+
.unwrap_err();
2081+
assert_eq!(error.code(), tonic::Code::ResourceExhausted);
2082+
assert!(stream.next().await.is_none());
2083+
assert_eq!(state.discovery_watches.available_permits(), 32);
2084+
drop(blockers);
2085+
assert!(
2086+
state
2087+
.discovery
2088+
.admit(&principal, &["default".into(), "later".into()], true)
2089+
.is_ok()
2090+
);
2091+
}
20282092
}

‎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
@@ -2091,3 +2091,9 @@ For rotation, add the replacement fingerprint, project the new certificate/key
20912091
to the consumer, then remove the old fingerprint. The proxy reloads mounted
20922092
identity and trust files on reconnect. No certificate issuance or renewal is
20932093
performed by the gateway.
2094+
2095+
Finite and all-workspace watches reserve capacity for every selected active
2096+
workspace. When that set changes, the watch reacquires workspace capacity before
2097+
publishing the next view. A newly selected workspace at capacity returns
2098+
`RESOURCE_EXHAUSTED`; the client can reconnect. Installation-record limits apply
2099+
per workspace; route and response-size limits also apply to the combined view.

0 commit comments

Comments
 (0)