Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into na-client-backpress…
Browse files Browse the repository at this point in the history
…ure-support
  • Loading branch information
niklasad1 committed Aug 1, 2023
2 parents ad91354 + b9b30fa commit aa7fff1
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/benchmarks_gitlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:

- name: Checkout Sources
uses: actions/checkout@v3.5.2
uses: actions/checkout@v3.5.3
with:
fetch-depth: 0
ref: "gh-pages"
Expand All @@ -24,7 +24,7 @@ jobs:
override: true

- name: Rust Cache
uses: Swatinem/rust-cache@v2.4.0
uses: Swatinem/rust-cache@v2.5.1

- name: Copy bench results
id: step_one
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3.5.2
- uses: actions/checkout@v3.5.3

- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1.0.7
Expand All @@ -34,7 +34,7 @@ jobs:
components: clippy, rustfmt

- name: Rust Cache
uses: Swatinem/rust-cache@v2.4.0
uses: Swatinem/rust-cache@v2.5.1

- name: Cargo fmt
uses: actions-rs/cargo@v1.0.3
Expand All @@ -53,7 +53,7 @@ jobs:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3.5.2
- uses: actions/checkout@v3.5.3

- name: Install Rust nightly toolchain
uses: actions-rs/toolchain@v1.0.7
Expand All @@ -70,7 +70,7 @@ jobs:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3.5.2
- uses: actions/checkout@v3.5.3

- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1.0.7
Expand All @@ -92,7 +92,7 @@ jobs:
version: 0.5

- name: Rust Cache
uses: Swatinem/rust-cache@v2.4.0
uses: Swatinem/rust-cache@v2.5.1

- name: Cargo check all targets and features
run: cargo hack check --workspace --each-feature --all-targets
Expand All @@ -105,7 +105,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3.5.2
uses: actions/checkout@v3.5.3

- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1.0.7
Expand All @@ -115,7 +115,7 @@ jobs:
override: true

- name: Rust Cache
uses: Swatinem/rust-cache@v2.4.0
uses: Swatinem/rust-cache@v2.5.1

- name: Cargo test
uses: actions-rs/cargo@v1.0.3
Expand All @@ -128,7 +128,7 @@ jobs:
runs-on: macos-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3.5.2
uses: actions/checkout@v3.5.3

- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1.0.7
Expand All @@ -138,7 +138,7 @@ jobs:
override: true

- name: Rust Cache
uses: Swatinem/rust-cache@v2.4.0
uses: Swatinem/rust-cache@v2.5.1

- name: Cargo test
uses: actions-rs/cargo@v1.0.3
Expand All @@ -151,7 +151,7 @@ jobs:
runs-on: windows-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3.5.2
uses: actions/checkout@v3.5.3

- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1.0.7
Expand All @@ -161,7 +161,7 @@ jobs:
override: true

- name: Rust Cache
uses: Swatinem/rust-cache@v2.4.0
uses: Swatinem/rust-cache@v2.5.1

- name: Cargo test
uses: actions-rs/cargo@v1.0.3
Expand All @@ -174,7 +174,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3.5.2
- uses: actions/checkout@v3.5.3

- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ variables:
GIT_STRATEGY: fetch
GIT_DEPTH: 100
CARGO_INCREMENTAL: 0
CI_IMAGE: "paritytech/ci-linux:production"
CI_IMAGE: "paritytech/ci-unified:bullseye-1.71.0-2023-05-23"

.common-refs: &common-refs
rules:
Expand Down
23 changes: 20 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@ The format is based on [Keep a Changelog].

[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [v0.19.0] - 2023-07-20

### [Fixed]

- Fixed connections processing await on server shutdown ([#1153](https://github.com/paritytech/jsonrpsee/pull/1153))
- fix: include error code in RpcLogger ([#1135](https://github.com/paritytech/jsonrpsee/pull/1135))
- fix: downgrade more logs to `debug` ([#1127](https://github.com/paritytech/jsonrpsee/pull/1127))
- fix(server): remove `MethodSinkPermit` to fix backpressure issue on concurrent subscriptions ([#1126](https://github.com/paritytech/jsonrpsee/pull/1126))
- fix readme links ([#1152](https://github.com/paritytech/jsonrpsee/pull/1152))

### [Changed]

- server: downgrade connection logs to debug ([#1123](https://github.com/paritytech/jsonrpsee/pull/1123))
- refactor(server): make `Server::start` infallible and add `fn builder()` ([#1137](https://github.com/paritytech/jsonrpsee/pull/1137))

## [v0.18.2] - 2023-05-10

This release improves error message for `too big batch response` and exposes the `BatchRequestConfig type` in order to make it possible to use `ServerBuilder::set_batch_request_config`

### Fixed
### [Fixed]

- server: export BatchRequestConfig ([#1112](https://github.com/paritytech/jsonrpsee/pull/1112))
- fix(server): improve too big batch response msg ([#1107](https://github.com/paritytech/jsonrpsee/pull/1107))

Expand All @@ -18,10 +33,12 @@ This release improves error message for `too big batch response` and exposes the
This release fixes a couple bugs and improves the ergonomics for the HTTP client
when no tower middleware is enabled.

### Changed
### [Changed]

- http client: add default generic param for the backend ([#1099](https://github.com/paritytech/jsonrpsee/pull/1099))

### Fixed
### [Fixed]

- rpc module: fix race in subscription close callback ([#1098](https://github.com/paritytech/jsonrpsee/pull/1098))
- client: add missing batch request tracing span ([#1097](https://github.com/paritytech/jsonrpsee/pull/1097))
- ws server: don't wait for graceful shutdown when connection already closed ([#1103](https://github.com/paritytech/jsonrpsee/pull/1103))
Expand Down
18 changes: 9 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ resolver = "2"

[workspace.package]
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
version = "0.18.2"
version = "0.19.0"
edition = "2021"
rust-version = "1.64.0"
license = "MIT"
Expand All @@ -30,11 +30,11 @@ keywords = ["jsonrpc", "json", "http", "websocket", "WASM"]
readme = "README.md"

[workspace.dependencies]
jsonrpsee-types = { path = "types", version = "0.18.2" }
jsonrpsee-core = { path = "core", version = "0.18.2" }
jsonrpsee-server = { path = "server", version = "0.18.2" }
jsonrpsee-ws-client = { path = "client/ws-client", version = "0.18.2" }
jsonrpsee-http-client = { path = "client/http-client", version = "0.18.2" }
jsonrpsee-wasm-client = { path = "client/wasm-client", version = "0.18.2" }
jsonrpsee-client-transport = { path = "client/transport", version = "0.18.2" }
jsonrpsee-proc-macros = { path = "proc-macros", version = "0.18.2" }
jsonrpsee-types = { path = "types", version = "0.19.0" }
jsonrpsee-core = { path = "core", version = "0.19.0" }
jsonrpsee-server = { path = "server", version = "0.19.0" }
jsonrpsee-ws-client = { path = "client/ws-client", version = "0.19.0" }
jsonrpsee-http-client = { path = "client/http-client", version = "0.19.0" }
jsonrpsee-wasm-client = { path = "client/wasm-client", version = "0.19.0" }
jsonrpsee-client-transport = { path = "client/transport", version = "0.19.0" }
jsonrpsee-proc-macros = { path = "proc-macros", version = "0.19.0" }
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# jsonrpsee

[![GitLab Status](https://gitlab.parity.io/parity/jsonrpsee/badges/master/pipeline.svg)](https://gitlab.parity.io/parity/jsonrpsee/pipelines)
[![GitLab Status](https://gitlab.parity.io/parity/mirrors/jsonrpsee/badges/master/pipeline.svg)](https://gitlab.parity.io/parity/mirrors/jsonrpsee/-/pipelines)
[![crates.io](https://img.shields.io/crates/v/jsonrpsee)](https://crates.io/crates/jsonrpsee)
[![Docs](https://docs.rs/jsonrpsee/badge.svg)](https://docs.rs/jsonrpsee)
![MIT](https://img.shields.io/crates/l/jsonrpsee.svg)
[![CI](https://github.com/paritytech/jsonrpsee/actions/workflows/ci.yml/badge.svg)](https://github.com/paritytech/jsonrpsee/actions/workflows/ci.yml)
[![Benchmarks](https://github.com/paritytech/jsonrpsee/actions/workflows/benchmarks.yml/badge.svg)](https://github.com/paritytech/jsonrpsee/actions/workflows/benchmarks.yml)
[![Benchmarks](https://github.com/paritytech/jsonrpsee/actions/workflows/benchmarks_gitlab.yml/badge.svg)](https://github.com/paritytech/jsonrpsee/actions/workflows/benchmarks_gitlab.yml)
[![dependency status](https://deps.rs/crate/jsonrpsee/0.18.1/status.svg)](https://deps.rs/crate/jsonrpsee/0.18.1)

JSON-RPC library designed for async/await in Rust.
Expand Down Expand Up @@ -50,7 +50,8 @@ If your project uses `jsonrpsee` we would like to know. Please open a pull reque
- [subwasm](https://github.com/chevdor/subwasm)
- [subway](https://github.com/AcalaNetwork/subway)
- [subxt](https://github.com/paritytech/subxt)
- [Trin](https://github.com/ethereum/trin)
- [Trin](https://github.com/ethereum/trin)
- [Uptest](https://github.com/uptest-sc/uptest)

## Benchmarks

Expand Down
4 changes: 2 additions & 2 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ license.workspace = true
publish = false

[dependencies]
pprof = { version = "0.11", features = ["flamegraph", "criterion"] }
criterion = { version = "0.4", features = ["async_tokio", "html_reports"] }
pprof = { version = "0.12", features = ["flamegraph", "criterion"] }
criterion = { version = "0.5", features = ["async_tokio", "html_reports"] }
futures-util = "0.3.15"
jsonrpsee = { path = "../jsonrpsee", features = ["server"] }
jsonrpsee_v0_15 = { package = "jsonrpsee", version = "=0.15.1", features = ["http-client", "ws-client", "client-ws-transport"] }
Expand Down
4 changes: 2 additions & 2 deletions client/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ pin-project = { version = "1", optional = true }

# tls
rustls-native-certs = { version = "0.6", optional = true }
webpki-roots = { version = "0.23", optional = true }
webpki-roots = { version = "0.25", optional = true }
tokio-rustls = { version = "0.24", optional = true }

# ws
soketto = { version = "0.7.1", optional = true }

# web-sys
gloo-net = { version = "0.2.6", default-features = false, features = ["json", "websocket"], optional = true }
gloo-net = { version = "0.3.0", default-features = false, features = ["json", "websocket"], optional = true }

[features]
native-tls = ["rustls-native-certs", "__tls"]
Expand Down
2 changes: 1 addition & 1 deletion client/transport/src/ws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ fn build_tls_config(cert_store: &CertificateStore) -> Result<tokio_rustls::TlsCo
}
#[cfg(feature = "webpki-tls")]
CertificateStore::WebPki => {
roots.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.0.iter().map(|ta| {
roots.add_server_trust_anchors(webpki_roots::TLS_SERVER_ROOTS.iter().map(|ta| {
rustls::OwnedTrustAnchor::from_subject_spki_name_constraints(ta.subject, ta.spki, ta.name_constraints)
}));
}
Expand Down
3 changes: 3 additions & 0 deletions proc-macros/tests/ui/incorrect/rpc/rpc_empty_bounds.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ error[E0277]: the trait bound `for<'de> <Conf as Config>::Hash: Deserialize<'de>
note: required by a bound in `request`
--> $WORKSPACE/core/src/client/mod.rs
|
| async fn request<R, Params>(&self, method: &str, params: Params) -> Result<R, Error>
| ------- required by a bound in this associated function
| where
| R: DeserializeOwned,
| ^^^^^^^^^^^^^^^^ required by this bound in `ClientT::request`
= note: this error originates in the attribute macro `rpc` (in Nightly builds, run with -Z macro-backtrace for more info)
40 changes: 28 additions & 12 deletions server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use crate::transport::{http, ws};
use futures_util::future::{self, Either, FutureExt};
use futures_util::io::{BufReader, BufWriter};

use futures_util::stream::{FuturesUnordered, StreamExt};
use hyper::body::HttpBody;
use jsonrpsee_core::id_providers::RandomIntegerIdProvider;

Expand All @@ -49,7 +48,7 @@ use jsonrpsee_core::{http_helpers, Error, TEN_MB_SIZE_BYTES};

use soketto::handshake::http::is_upgrade_request;
use tokio::net::{TcpListener, TcpStream, ToSocketAddrs};
use tokio::sync::{watch, OwnedSemaphorePermit};
use tokio::sync::{mpsc, watch, OwnedSemaphorePermit};
use tokio_util::compat::TokioAsyncReadCompatExt;
use tower::layer::util::Identity;
use tower::{Layer, Service};
Expand Down Expand Up @@ -137,10 +136,11 @@ where
let connection_guard = ConnectionGuard::new(self.cfg.max_connections as usize);
let listener = self.listener;

let mut connections = FuturesUnordered::new();
let stopped = stop_handle.clone().shutdown();
tokio::pin!(stopped);

let (drop_on_completion, mut process_connection_awaiter) = mpsc::channel::<()>(1);

loop {
match try_accept_conn(&listener, stopped).await {
AcceptConnection::Established { socket, remote_addr, stop } => {
Expand All @@ -163,7 +163,14 @@ where
enable_ws: self.cfg.enable_ws,
message_buffer_capacity: self.cfg.message_buffer_capacity,
};
process_connection(&self.service_builder, &connection_guard, data, socket, &mut connections);

process_connection(
&self.service_builder,
&connection_guard,
data,
socket,
drop_on_completion.clone(),
);
id = id.wrapping_add(1);
stopped = stop;
}
Expand All @@ -175,11 +182,14 @@ where
}
}

// FuturesUnordered won't poll anything until this line but because the
// tasks are spawned (so that they can progress independently)
// then this just makes sure that all tasks are completed before
// returning from this function.
while connections.next().await.is_some() {}
// Drop the last Sender
drop(drop_on_completion);

// Once this channel is closed it is safe to assume that all connections have been gracefully shutdown
while process_connection_awaiter.recv().await.is_some() {
// Generally, messages should not be sent across this channel,
// but we'll loop here to wait for `None` just to be on the safe side
}
}
}

Expand Down Expand Up @@ -743,7 +753,7 @@ fn process_connection<'a, L: Logger, B, U>(
connection_guard: &ConnectionGuard,
cfg: ProcessConnection<L>,
socket: TcpStream,
connections: &mut FuturesUnordered<tokio::task::JoinHandle<()>>,
drop_on_completion: mpsc::Sender<()>,
) where
B: Layer<TowerService<L>> + Send + 'static,
<B as Layer<TowerService<L>>>::Service: Send
Expand All @@ -766,7 +776,10 @@ fn process_connection<'a, L: Logger, B, U>(
Some(conn) => conn,
None => {
tracing::debug!("Too many connections. Please try again later.");
connections.push(tokio::spawn(http::reject_connection(socket).in_current_span()));
tokio::spawn(async {
http::reject_connection(socket).in_current_span().await;
drop(drop_on_completion);
});
return;
}
};
Expand Down Expand Up @@ -799,7 +812,10 @@ fn process_connection<'a, L: Logger, B, U>(

let service = service_builder.service(tower_service);

connections.push(tokio::spawn(to_http_service(socket, service, cfg.stop_handle).in_current_span()));
tokio::spawn(async {
to_http_service(socket, service, cfg.stop_handle).in_current_span().await;
drop(drop_on_completion)
});
}

// Attempts to create a HTTP connection from a socket.
Expand Down

0 comments on commit aa7fff1

Please sign in to comment.