MCPcopy Create free account
hub / github.com/hashintel/hash / start_rpc_server

Function start_rpc_server

apps/hash-graph/src/subcommand/server.rs:256–312  ·  view source on GitHub ↗
(
    address: RpcAddress,
    dependencies: Dependencies<S, ()>,
    lifecycle: &ServerLifecycle,
)

Source from the content-addressed store, hash-verified

254}
255
256fn start_rpc_server<S>(
257 address: RpcAddress,
258 dependencies: Dependencies<S, ()>,
259 lifecycle: &ServerLifecycle,
260) -> Result<(), Report<GraphError>>
261where
262 S: StorePool + Send + Sync + 'static,
263 for<'p> S::Store<'p>: PrincipalStore,
264{
265 let server = Server::new(harpc_server::ServerConfig::default()).change_context(GraphError)?;
266 let cancellation_token = server.cancellation_token();
267
268 let (router, task) = hash_graph_api::rpc::rpc_router(
269 Dependencies {
270 store: dependencies.store,
271 temporal_client: dependencies.temporal_client,
272 codec: JsonCodec,
273 },
274 server.events(),
275 );
276
277 lifecycle.spawn("RPC task", async move {
278 task.await;
279 Ok(())
280 });
281
282 // Bridge: when our shutdown token fires, cancel the harpc server's internal token
283 let shutdown = lifecycle.shutdown.clone();
284 lifecycle.spawn("RPC shutdown bridge", async move {
285 shutdown.cancelled().await;
286 cancellation_token.cancel();
287 Ok(())
288 });
289
290 let socket_address: SocketAddr = SocketAddr::try_from(address).change_context(GraphError)?;
291 let mut address = Multiaddr::empty();
292 match socket_address {
293 SocketAddr::V4(v4) => {
294 address.push(Protocol::Ip4(*v4.ip()));
295 address.push(Protocol::Tcp(v4.port()));
296 }
297 SocketAddr::V6(v6) => {
298 address.push(Protocol::Ip6(*v6.ip()));
299 address.push(Protocol::Tcp(v6.port()));
300 }
301 }
302
303 #[expect(clippy::significant_drop_tightening, reason = "false positive")]
304 lifecycle.spawn("RPC server", async move {
305 let stream = server.listen(address).await.change_context(GraphError)?;
306
307 harpc_server::serve::serve(stream, router).await;
308 Ok(())
309 });
310
311 Ok(())
312}
313

Callers 1

start_serverFunction · 0.85

Calls 15

rpc_routerFunction · 0.85
OkInterface · 0.85
try_fromFunction · 0.85
serveFunction · 0.85
portMethod · 0.80
cancelMethod · 0.65
pushMethod · 0.65
defaultFunction · 0.50
emptyFunction · 0.50
change_contextMethod · 0.45
cancellation_tokenMethod · 0.45
eventsMethod · 0.45

Tested by

no test coverage detected