From: Kefu Chai Date: Sat, 20 Feb 2021 08:49:19 +0000 (+0800) Subject: crimson/net: throw read_eof if short read X-Git-Tag: v17.1.0~2913^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F39592%2Fhead;p=ceph.git crimson/net: throw read_eof if short read as per the implementation and the document of input_stream::read_exactly(): /// stream and returns them. If the end of stream is reached before n /// bytes were read, fewer than n bytes will be returned - so despite /// the method's name, the caller must not assume the returned buffer /// will always contain exactly n bytes. Signed-off-by: Kefu Chai --- diff --git a/src/crimson/net/Socket.cc b/src/crimson/net/Socket.cc index 8ad106dbdd7..990c191a250 100644 --- a/src/crimson/net/Socket.cc +++ b/src/crimson/net/Socket.cc @@ -92,8 +92,8 @@ Socket::read_exactly(size_t bytes) { if (bytes == 0) { return seastar::make_ready_future>(); } - return in.read_exactly(bytes).then([](auto buf) { - if (buf.empty()) { + return in.read_exactly(bytes).then([bytes](auto buf) { + if (buf.size() < bytes) { throw std::system_error(make_error_code(error::read_eof)); } return seastar::make_ready_future(std::move(buf));