Skip to content

Commit

Permalink
Merge pull request #4331 from chenyukang/yukang-fix-websocks-terminate
Browse files Browse the repository at this point in the history
Fix the websockets terminate issue
  • Loading branch information
chenyukang authored Jan 30, 2024
2 parents 8e81649 + cbb76da commit c012030
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions rpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ impl RpcServer {
) -> Result<SocketAddr, AnyError> {
let stream_config = StreamServerConfig::default()
.with_keep_alive(true)
.with_channel_size(4)
.with_pipeline_size(4);
.with_pipeline_size(4)
.with_shutdown(async move {
new_tokio_exit_rx().cancelled().await;
});

// HTTP and WS server.
let post_router = post(handle_jsonrpc::<Option<Session>>);
Expand All @@ -100,24 +102,14 @@ impl RpcServer {
};
let method_router = post_router.merge(get_router);

let mut app = Router::new()
let app = Router::new()
.route("/", method_router.clone())
.route("/*path", method_router)
.route("/ping", get(ping_handler))
.layer(Extension(Arc::clone(rpc)))
.layer(CorsLayer::permissive())
.layer(TimeoutLayer::new(Duration::from_secs(30)))
.layer(Extension(stream_config.clone()));

if enable_websocket {
let ws_config: StreamServerConfig =
stream_config
.with_keep_alive(true)
.with_shutdown(async move {
new_tokio_exit_rx().cancelled().await;
});
app = app.layer(Extension(ws_config));
}
.layer(Extension(stream_config));

let (tx_addr, rx_addr) = tokio::sync::oneshot::channel::<SocketAddr>();

Expand Down

0 comments on commit c012030

Please sign in to comment.