Skip to content

Commit 2135c25

Browse files
authored
Avoid closing HTTP server on connection error (#515)
* Avoid killing the server if failing connection fails. * Add a tests. * Bump version.
1 parent a22e0db commit 2135c25

16 files changed

Lines changed: 57 additions & 13 deletions

File tree

core-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ keywords = ["jsonrpc", "json-rpc", "json", "rpc", "serde"]
88
license = "MIT"
99
name = "jsonrpc-core-client"
1010
repository = "https://github.com/paritytech/jsonrpc"
11-
version = "14.0.2"
11+
version = "14.0.3"
1212

1313
categories = [
1414
"asynchronous",

core-client/transports/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ keywords = ["jsonrpc", "json-rpc", "json", "rpc", "serde"]
88
license = "MIT"
99
name = "jsonrpc-client-transports"
1010
repository = "https://github.com/paritytech/jsonrpc"
11-
version = "14.0.2"
11+
version = "14.0.3"
1212

1313
categories = [
1414
"asynchronous",

core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ keywords = ["jsonrpc", "json-rpc", "json", "rpc", "serde"]
88
license = "MIT"
99
name = "jsonrpc-core"
1010
repository = "https://github.com/paritytech/jsonrpc"
11-
version = "14.0.2"
11+
version = "14.0.3"
1212

1313
categories = [
1414
"asynchronous",

derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ homepage = "https://github.com/paritytech/jsonrpc"
77
license = "MIT"
88
name = "jsonrpc-derive"
99
repository = "https://github.com/paritytech/jsonrpc"
10-
version = "14.0.2"
10+
version = "14.0.3"
1111

1212
[lib]
1313
proc-macro = true

http/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ keywords = ["jsonrpc", "json-rpc", "json", "rpc", "server"]
88
license = "MIT"
99
name = "jsonrpc-http-server"
1010
repository = "https://github.com/paritytech/jsonrpc"
11-
version = "14.0.2"
11+
version = "14.0.3"
1212

1313
[dependencies]
1414
hyper = "0.12"
@@ -18,5 +18,9 @@ log = "0.4"
1818
net2 = "0.2"
1919
unicase = "2.0"
2020
parking_lot = "0.9.0"
21+
22+
[dev-dependencies]
23+
env_logger = "0.6"
24+
2125
[badges]
2226
travis-ci = { repository = "paritytech/jsonrpc", branch = "master"}

http/examples/server.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use jsonrpc_http_server::jsonrpc_core::*;
22
use jsonrpc_http_server::{AccessControlAllowOrigin, DomainsValidation, RestApi, ServerBuilder};
33

44
fn main() {
5+
env_logger::init();
6+
57
let mut io = IoHandler::default();
68
io.add_method("say_hello", |_params: Params| Ok(Value::String("hello".to_string())));
79

http/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ fn serve<M: jsonrpc::Metadata, S: jsonrpc::Middleware<M>>(
555555

556556
http.serve_connection(socket, service)
557557
.map_err(|e| error!("Error serving connection: {:?}", e))
558+
.then(|_| Ok(()))
558559
})
559560
.buffer_unordered(1024)
560561
.for_each(|_| Ok(()))

http/src/tests.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,43 @@ fn should_drop_io_handler_when_server_is_closed() {
15291529
panic!("expected server to be closed and io handler to be dropped")
15301530
}
15311531

1532+
#[test]
1533+
fn should_not_close_server_when_serving_errors() {
1534+
// given
1535+
let server = serve(|builder| builder.keep_alive(false));
1536+
let addr = server.address().clone();
1537+
1538+
// when
1539+
let req = "{}";
1540+
let request = format!(
1541+
"\
1542+
POST / HTTP/1.1\r\n\
1543+
Host: localhost:{}\r\n\
1544+
Content-Type: application/json\r\n\
1545+
Content-Length: {}\r\n\
1546+
😈: 😈\r\n\
1547+
\r\n\
1548+
{}\r\n\
1549+
",
1550+
addr.port(),
1551+
req.as_bytes().len(),
1552+
req
1553+
);
1554+
1555+
let mut req = TcpStream::connect(addr).unwrap();
1556+
req.write_all(request.as_bytes()).unwrap();
1557+
let mut response = String::new();
1558+
req.read_to_string(&mut response).unwrap();
1559+
assert!(!response.is_empty(), "Response should not be empty: {}", response);
1560+
1561+
// then make a second request and it must not fail.
1562+
let mut req = TcpStream::connect(addr).unwrap();
1563+
req.write_all(request.as_bytes()).unwrap();
1564+
let mut response = String::new();
1565+
req.read_to_string(&mut response).unwrap();
1566+
assert!(!response.is_empty(), "Response should not be empty: {}", response);
1567+
}
1568+
15321569
fn invalid_host() -> String {
15331570
"Provided Host header is not whitelisted.\n".into()
15341571
}

ipc/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ homepage = "https://github.com/paritytech/jsonrpc"
77
license = "MIT"
88
name = "jsonrpc-ipc-server"
99
repository = "https://github.com/paritytech/jsonrpc"
10-
version = "14.0.2"
10+
version = "14.0.3"
1111

1212
[dependencies]
1313
log = "0.4"

pubsub/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ keywords = ["jsonrpc", "json-rpc", "json", "rpc", "macros"]
88
license = "MIT"
99
name = "jsonrpc-pubsub"
1010
repository = "https://github.com/paritytech/jsonrpc"
11-
version = "14.0.2"
11+
version = "14.0.3"
1212

1313
[dependencies]
1414
log = "0.4"

0 commit comments

Comments
 (0)