Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the websockets terminate issue #4331

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading