Fix ping test in request-response. (#1702)

The codec impl did not check that it actually read any bytes in
`read_request` and `read_response`. The used `read_one` function
does not error on EOF either, so instead of signalling connection
loss the codec could produce empty `Ping` or `Pong` messages.
This commit is contained in:
Toralf Wittner 2020-08-13 12:49:16 +02:00 committed by GitHub
parent 0d26f50304
commit 7d47ada077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -356,8 +356,11 @@ impl RequestResponseCodec for PingCodec {
T: AsyncRead + Unpin + Send T: AsyncRead + Unpin + Send
{ {
read_one(io, 1024) read_one(io, 1024)
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .map(|res| match res {
.map_ok(Ping) Err(e) => Err(io::Error::new(io::ErrorKind::InvalidData, e)),
Ok(vec) if vec.is_empty() => Err(io::ErrorKind::UnexpectedEof.into()),
Ok(vec) => Ok(Ping(vec))
})
.await .await
} }
@ -367,8 +370,11 @@ impl RequestResponseCodec for PingCodec {
T: AsyncRead + Unpin + Send T: AsyncRead + Unpin + Send
{ {
read_one(io, 1024) read_one(io, 1024)
.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) .map(|res| match res {
.map_ok(Pong) Err(e) => Err(io::Error::new(io::ErrorKind::InvalidData, e)),
Ok(vec) if vec.is_empty() => Err(io::ErrorKind::UnexpectedEof.into()),
Ok(vec) => Ok(Pong(vec))
})
.await .await
} }