You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2016/05/04 00:37:06 UTC
[1/2] incubator-kudu git commit: rpc: avoid crashing if the server
generates an invalid RPC response
Repository: incubator-kudu
Updated Branches:
refs/heads/master 95eb5d591 -> d3eb2d8f4
rpc: avoid crashing if the server generates an invalid RPC response
This prevents a server-wide crash in the case that an RPC handler tries to
respond with an invalid protobuf (e.g. missing a required field).
We used to have a DFATAL in this case, which would log an error, but then
proceed to crash immediately thereafter because the response buffer was empty.
The new behavior is for the server side to log the error, and then send
the partial protobuf back to the client anyway. The client will see
the same issue upon parsing the response, and generate an error to
the caller indicating the missing fields. This has the benefit that
the error will be logged on both sides, and that the server won't crash.
This also changes the behavior on the client side when trying to send
an invalid RPC. Again, we send it even though it's incomplete, but
expect the server to reject it.
Change-Id: Ia7845388b1f520158e554548d668836d40b10ca6
Reviewed-on: http://gerrit.cloudera.org:8080/2914
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/b6883332
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/b6883332
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/b6883332
Branch: refs/heads/master
Commit: b6883332d3a5ac538ae987c602a64bbc8416b791
Parents: 95eb5d5
Author: Todd Lipcon <to...@apache.org>
Authored: Sat Apr 30 12:29:56 2016 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Tue May 3 22:36:20 2016 +0000
----------------------------------------------------------------------
src/kudu/rpc/blocking_ops.cc | 4 +--
src/kudu/rpc/inbound_call.cc | 30 +++++++++++---------
src/kudu/rpc/inbound_call.h | 4 +--
src/kudu/rpc/outbound_call.cc | 8 +++---
src/kudu/rpc/outbound_call.h | 2 +-
src/kudu/rpc/proxy.cc | 8 +-----
src/kudu/rpc/rpc-test-base.h | 16 +++++++++++
src/kudu/rpc/rpc_stub-test.cc | 20 +++++++++++--
src/kudu/rpc/rtest.proto | 13 +++++++++
src/kudu/rpc/serialization.cc | 26 +++++------------
src/kudu/rpc/serialization.h | 12 ++++----
src/kudu/rpc/service_if.cc | 2 +-
.../tserver/remote_bootstrap_service-test.cc | 11 +++++--
13 files changed, 95 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/blocking_ops.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/blocking_ops.cc b/src/kudu/rpc/blocking_ops.cc
index 923d855..6add2e8 100644
--- a/src/kudu/rpc/blocking_ops.cc
+++ b/src/kudu/rpc/blocking_ops.cc
@@ -63,11 +63,11 @@ Status SendFramedMessageBlocking(Socket* sock, const MessageLite& header, const
// Serialize message
faststring param_buf;
- RETURN_NOT_OK(serialization::SerializeMessage(msg, ¶m_buf));
+ serialization::SerializeMessage(msg, ¶m_buf);
// Serialize header and initial length
faststring header_buf;
- RETURN_NOT_OK(serialization::SerializeHeader(header, param_buf.size(), &header_buf));
+ serialization::SerializeHeader(header, param_buf.size(), &header_buf);
// Write header & param to stream
size_t nsent;
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/inbound_call.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/inbound_call.cc b/src/kudu/rpc/inbound_call.cc
index 644116a..95cbb70 100644
--- a/src/kudu/rpc/inbound_call.cc
+++ b/src/kudu/rpc/inbound_call.cc
@@ -123,11 +123,7 @@ void InboundCall::ApplicationErrorToPB(int error_ext_id, const std::string& mess
void InboundCall::Respond(const MessageLite& response,
bool is_success) {
TRACE_EVENT_FLOW_END0("rpc", "InboundCall", this);
- Status s = SerializeResponseBuffer(response, is_success);
- if (PREDICT_FALSE(!s.ok())) {
- // TODO: test error case, serialize error response instead
- LOG(DFATAL) << "Unable to serialize response: " << s.ToString();
- }
+ SerializeResponseBuffer(response, is_success);
TRACE_EVENT_ASYNC_END1("rpc", "InboundCall", this,
"method", remote_method_.method_name());
@@ -137,8 +133,18 @@ void InboundCall::Respond(const MessageLite& response,
conn_->QueueResponseForCall(gscoped_ptr<InboundCall>(this));
}
-Status InboundCall::SerializeResponseBuffer(const MessageLite& response,
- bool is_success) {
+void InboundCall::SerializeResponseBuffer(const MessageLite& response,
+ bool is_success) {
+ if (PREDICT_FALSE(!response.IsInitialized())) {
+ LOG(ERROR) << "Invalid RPC response for " << ToString()
+ << ": protobuf missing required fields: "
+ << response.InitializationErrorString();
+ // Send it along anyway -- the client will also notice the missing fields
+ // and produce an error on the other side, but this will at least
+ // make it clear on both sides of the RPC connection what kind of error
+ // happened.
+ }
+
uint32_t protobuf_msg_size = response.ByteSize();
ResponseHeader resp_hdr;
@@ -151,13 +157,11 @@ Status InboundCall::SerializeResponseBuffer(const MessageLite& response,
}
int additional_size = absolute_sidecar_offset - protobuf_msg_size;
- RETURN_NOT_OK(serialization::SerializeMessage(response, &response_msg_buf_,
- additional_size, true));
+ serialization::SerializeMessage(response, &response_msg_buf_,
+ additional_size, true);
int main_msg_size = additional_size + response_msg_buf_.size();
- RETURN_NOT_OK(serialization::SerializeHeader(resp_hdr, main_msg_size,
- &response_hdr_buf_));
-
- return Status::OK();
+ serialization::SerializeHeader(resp_hdr, main_msg_size,
+ &response_hdr_buf_);
}
void InboundCall::SerializeResponseTo(vector<Slice>* slices) const {
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/inbound_call.h
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/inbound_call.h b/src/kudu/rpc/inbound_call.h
index 7796ef9..ac18e39 100644
--- a/src/kudu/rpc/inbound_call.h
+++ b/src/kudu/rpc/inbound_call.h
@@ -197,8 +197,8 @@ class InboundCall {
// Serialize a response message for either success or failure. If it is a success,
// 'response' should be the user-defined response type for the call. If it is a
// failure, 'response' should be an ErrorStatusPB instance.
- Status SerializeResponseBuffer(const google::protobuf::MessageLite& response,
- bool is_success);
+ void SerializeResponseBuffer(const google::protobuf::MessageLite& response,
+ bool is_success);
// When RPC call Handle() completed execution on the server side.
// Updates the Histogram with time elapsed since the call was started,
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/outbound_call.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/outbound_call.cc b/src/kudu/rpc/outbound_call.cc
index 5b7fbd8..e787aac 100644
--- a/src/kudu/rpc/outbound_call.cc
+++ b/src/kudu/rpc/outbound_call.cc
@@ -96,7 +96,7 @@ Status OutboundCall::SerializeTo(vector<Slice>* slices) {
header_.add_required_feature_flags(feature);
}
- CHECK_OK(serialization::SerializeHeader(header_, param_len, &header_buf_));
+ serialization::SerializeHeader(header_, param_len, &header_buf_);
// Return the concatenated packet.
slices->push_back(Slice(header_buf_));
@@ -112,8 +112,8 @@ set<RpcFeatureFlag> OutboundCall::RequiredRpcFeatures() const {
return s;
}
-Status OutboundCall::SetRequestParam(const Message& message) {
- return serialization::SerializeMessage(message, &request_buf_);
+void OutboundCall::SetRequestParam(const Message& message) {
+ serialization::SerializeMessage(message, &request_buf_);
}
Status OutboundCall::status() const {
@@ -212,7 +212,7 @@ void OutboundCall::SetResponse(gscoped_ptr<CallResponse> resp) {
// which isn't great, since it would block processing of other RPCs in parallel.
// Should look into a way to avoid this.
if (!response_->ParseFromArray(r.data(), r.size())) {
- SetFailed(Status::IOError("Invalid response, missing fields",
+ SetFailed(Status::IOError("invalid RPC response, missing fields",
response_->InitializationErrorString()));
return;
}
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/outbound_call.h
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/outbound_call.h b/src/kudu/rpc/outbound_call.h
index 3e65e52..33ea2a7 100644
--- a/src/kudu/rpc/outbound_call.h
+++ b/src/kudu/rpc/outbound_call.h
@@ -169,7 +169,7 @@ class OutboundCall {
//
// Because the data is fully serialized by this call, 'req' may be
// subsequently mutated with no ill effects.
- Status SetRequestParam(const google::protobuf::Message& req);
+ void SetRequestParam(const google::protobuf::Message& req);
// Assign the call ID for this call. This is called from the reactor
// thread once a connection has been assigned. Must only be called once.
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/proxy.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/proxy.cc b/src/kudu/rpc/proxy.cc
index d2e7537..8337e31 100644
--- a/src/kudu/rpc/proxy.cc
+++ b/src/kudu/rpc/proxy.cc
@@ -79,13 +79,7 @@ void Proxy::AsyncRequest(const string& method,
RemoteMethod remote_method(service_name_, method);
OutboundCall* call = new OutboundCall(conn_id_, remote_method, response, controller, callback);
controller->call_.reset(call);
- Status s = call->SetRequestParam(req);
- if (PREDICT_FALSE(!s.ok())) {
- // Failed to serialize request: likely the request is missing a required
- // field.
- call->SetFailed(s); // calls callback internally
- return;
- }
+ call->SetRequestParam(req);
// If this fails to queue, the callback will get called immediately
// and the controller will be in an ERROR state.
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/rpc-test-base.h
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/rpc-test-base.h b/src/kudu/rpc/rpc-test-base.h
index 24bacdf..db174eb 100644
--- a/src/kudu/rpc/rpc-test-base.h
+++ b/src/kudu/rpc/rpc-test-base.h
@@ -59,6 +59,8 @@ using kudu::rpc_test::SendTwoStringsRequestPB;
using kudu::rpc_test::SendTwoStringsResponsePB;
using kudu::rpc_test::SleepRequestPB;
using kudu::rpc_test::SleepResponsePB;
+using kudu::rpc_test::TestInvalidResponseRequestPB;
+using kudu::rpc_test::TestInvalidResponseResponsePB;
using kudu::rpc_test::WhoAmIRequestPB;
using kudu::rpc_test::WhoAmIResponsePB;
using kudu::rpc_test_diff_package::ReqDiffPackagePB;
@@ -229,6 +231,20 @@ class CalculatorService : public CalculatorServiceIf {
PANIC_RPC(context, "Test method panicking!");
}
+ void TestInvalidResponse(const TestInvalidResponseRequestPB* req,
+ TestInvalidResponseResponsePB* resp,
+ RpcContext* context) override {
+ switch (req->error_type()) {
+ case rpc_test::TestInvalidResponseRequestPB_ErrorType_MISSING_REQUIRED_FIELD:
+ // Respond without setting the 'resp->response' protobuf field, which is
+ // marked as required. This exercises the error path of invalid responses.
+ context->RespondSuccess();
+ break;
+ default:
+ LOG(FATAL);
+ }
+ }
+
bool SupportsFeature(uint32_t feature) const override {
return feature == FeatureFlags::FOO;
}
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/rpc_stub-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/rpc_stub-test.cc b/src/kudu/rpc/rpc_stub-test.cc
index 00adf1e..d23d6ee 100644
--- a/src/kudu/rpc/rpc_stub-test.cc
+++ b/src/kudu/rpc/rpc_stub-test.cc
@@ -198,8 +198,9 @@ TEST_F(RpcStubTest, TestCallWithInvalidParam) {
Status s = p.SyncRequest("Add", req, &resp, &controller);
ASSERT_TRUE(s.IsRemoteError()) << "Bad status: " << s.ToString();
ASSERT_STR_CONTAINS(s.ToString(),
- "Invalid argument: Invalid parameter for call "
- "kudu.rpc_test.CalculatorService.Add: y");
+ "Invalid argument: invalid parameter for call "
+ "kudu.rpc_test.CalculatorService.Add: "
+ "missing fields: y");
}
// Wrapper around AtomicIncrement, since AtomicIncrement returns the 'old'
@@ -227,7 +228,20 @@ TEST_F(RpcStubTest, TestCallWithMissingPBFieldClientSide) {
SleepFor(MonoDelta::FromMicroseconds(100));
ASSERT_EQ(1, NoBarrier_Load(&callback_count));
ASSERT_STR_CONTAINS(controller.status().ToString(),
- "Invalid argument: RPC argument missing required fields: y");
+ "Invalid argument: invalid parameter for call "
+ "kudu.rpc_test.CalculatorService.Add: missing fields: y");
+}
+
+TEST_F(RpcStubTest, TestResponseWithMissingField) {
+ CalculatorServiceProxy p(client_messenger_, server_addr_);
+
+ RpcController rpc;
+ TestInvalidResponseRequestPB req;
+ TestInvalidResponseResponsePB resp;
+ req.set_error_type(rpc_test::TestInvalidResponseRequestPB_ErrorType_MISSING_REQUIRED_FIELD);
+ Status s = p.TestInvalidResponse(req, &resp, &rpc);
+ ASSERT_STR_CONTAINS(s.ToString(),
+ "invalid RPC response, missing fields: response");
}
// Test sending a call which isn't implemented by the server.
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/rtest.proto
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/rtest.proto b/src/kudu/rpc/rtest.proto
index 2c89877..076d2f6 100644
--- a/src/kudu/rpc/rtest.proto
+++ b/src/kudu/rpc/rtest.proto
@@ -90,6 +90,17 @@ message CalculatorError {
message PanicRequestPB {}
message PanicResponsePB {}
+message TestInvalidResponseRequestPB {
+ enum ErrorType {
+ MISSING_REQUIRED_FIELD = 1;
+ }
+ required ErrorType error_type = 1;
+}
+
+message TestInvalidResponseResponsePB {
+ required bytes response = 1;
+}
+
enum FeatureFlags {
UNKNOWN=0;
FOO=1;
@@ -103,4 +114,6 @@ service CalculatorService {
rpc TestArgumentsInDiffPackage(kudu.rpc_test_diff_package.ReqDiffPackagePB)
returns(kudu.rpc_test_diff_package.RespDiffPackagePB);
rpc Panic(PanicRequestPB) returns (PanicResponsePB);
+
+ rpc TestInvalidResponse(TestInvalidResponseRequestPB) returns (TestInvalidResponseResponsePB);
}
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/serialization.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/serialization.cc b/src/kudu/rpc/serialization.cc
index 3160c53..3ad46bc 100644
--- a/src/kudu/rpc/serialization.cc
+++ b/src/kudu/rpc/serialization.cc
@@ -44,13 +44,8 @@ enum {
kHeaderPosAuthProto = 2
};
-Status SerializeMessage(const MessageLite& message, faststring* param_buf,
+void SerializeMessage(const MessageLite& message, faststring* param_buf,
int additional_size, bool use_cached_size) {
-
- if (PREDICT_FALSE(!message.IsInitialized())) {
- return Status::InvalidArgument("RPC argument missing required fields",
- message.InitializationErrorString());
- }
int pb_size = use_cached_size ? message.GetCachedSize() : message.ByteSize();
DCHECK_EQ(message.ByteSize(), pb_size);
int recorded_size = pb_size + additional_size;
@@ -58,7 +53,7 @@ Status SerializeMessage(const MessageLite& message, faststring* param_buf,
int total_size = size_with_delim + additional_size;
if (total_size > FLAGS_rpc_max_message_size) {
- LOG(DFATAL) << "Sending too long of an RPC message (" << total_size
+ LOG(WARNING) << "Sending too long of an RPC message (" << total_size
<< " bytes)";
}
@@ -67,19 +62,14 @@ Status SerializeMessage(const MessageLite& message, faststring* param_buf,
dst = CodedOutputStream::WriteVarint32ToArray(recorded_size, dst);
dst = message.SerializeWithCachedSizesToArray(dst);
CHECK_EQ(dst, param_buf->data() + size_with_delim);
-
- return Status::OK();
}
-Status SerializeHeader(const MessageLite& header,
- size_t param_len,
- faststring* header_buf) {
+void SerializeHeader(const MessageLite& header,
+ size_t param_len,
+ faststring* header_buf) {
- if (PREDICT_FALSE(!header.IsInitialized())) {
- LOG(DFATAL) << "Uninitialized RPC header";
- return Status::InvalidArgument("RPC header missing required fields",
- header.InitializationErrorString());
- }
+ CHECK(header.IsInitialized())
+ << "RPC header missing fields: " << header.InitializationErrorString();
// Compute all the lengths for the packet.
size_t header_pb_len = header.ByteSize();
@@ -102,8 +92,6 @@ Status SerializeHeader(const MessageLite& header,
// We should have used the whole buffer we allocated.
CHECK_EQ(dst, header_buf->data() + header_tot_len);
-
- return Status::OK();
}
Status ParseMessage(const Slice& buf,
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/serialization.h
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/serialization.h b/src/kudu/rpc/serialization.h
index ed1275b..26df3a7 100644
--- a/src/kudu/rpc/serialization.h
+++ b/src/kudu/rpc/serialization.h
@@ -51,9 +51,9 @@ namespace serialization {
// needs to be serialized for the protobuf (i.e., no additional space
// is reserved for 'additional_size', which only affects the
// size indicator prefix in 'param_buf').
-Status SerializeMessage(const google::protobuf::MessageLite& message,
- faststring* param_buf, int additional_size = 0,
- bool use_cached_size = false);
+void SerializeMessage(const google::protobuf::MessageLite& message,
+ faststring* param_buf, int additional_size = 0,
+ bool use_cached_size = false);
// Serialize the request or response header into a buffer which is allocated
// by this function.
@@ -61,9 +61,9 @@ Status SerializeMessage(const google::protobuf::MessageLite& message,
// In: Protobuf Header to serialize,
// Length of the message param following this header in the frame.
// Out: faststring to be populated with the serialized bytes.
-Status SerializeHeader(const google::protobuf::MessageLite& header,
- size_t param_len,
- faststring* header_buf);
+void SerializeHeader(const google::protobuf::MessageLite& header,
+ size_t param_len,
+ faststring* header_buf);
// Deserialize the request.
// In: data buffer Slice.
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/rpc/service_if.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/service_if.cc b/src/kudu/rpc/service_if.cc
index 073b50b..41da8c2 100644
--- a/src/kudu/rpc/service_if.cc
+++ b/src/kudu/rpc/service_if.cc
@@ -48,7 +48,7 @@ bool ServiceIf::SupportsFeature(uint32_t feature) const {
bool ServiceIf::ParseParam(InboundCall *call, google::protobuf::Message *message) {
Slice param(call->serialized_request());
if (PREDICT_FALSE(!message->ParseFromArray(param.data(), param.size()))) {
- string err = Substitute("Invalid parameter for call $0: $1",
+ string err = Substitute("invalid parameter for call $0: missing fields: $1",
call->remote_method().ToString(),
message->InitializationErrorString().c_str());
LOG(WARNING) << err;
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/b6883332/src/kudu/tserver/remote_bootstrap_service-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tserver/remote_bootstrap_service-test.cc b/src/kudu/tserver/remote_bootstrap_service-test.cc
index 2149663..27faa59 100644
--- a/src/kudu/tserver/remote_bootstrap_service-test.cc
+++ b/src/kudu/tserver/remote_bootstrap_service-test.cc
@@ -150,7 +150,8 @@ class RemoteBootstrapServiceTest : public RemoteBootstrapTest {
// Enhance a RemoteError Status message with additional details from the remote.
Status UnwindRemoteError(Status status, const RpcController* controller) {
- if (!status.IsRemoteError()) {
+ if (!status.IsRemoteError() ||
+ controller->error_response()->code() != ErrorStatusPB::ERROR_APPLICATION) {
return status;
}
Status remote_error = ExtractRemoteError(controller->error_response());
@@ -285,14 +286,18 @@ TEST_F(RemoteBootstrapServiceTest, TestInvalidBlockOrOpId) {
}
// Empty data type with BlockId.
- // The RPC system will not let us send the required type field.
+ // The server will reject the request since we are missing the required 'type' field.
{
FetchDataResponsePB resp;
RpcController controller;
DataIdPB data_id;
data_id.mutable_block_id()->set_id(1);
Status status = DoFetchData(session_id, data_id, nullptr, nullptr, &resp, &controller);
- ASSERT_TRUE(status.IsInvalidArgument());
+ ASSERT_TRUE(status.IsRemoteError()) << status.ToString();
+ ASSERT_STR_CONTAINS(status.ToString(),
+ "Invalid argument: invalid parameter for call "
+ "kudu.tserver.RemoteBootstrapService.FetchData: "
+ "missing fields: data_id.type");
}
// Empty data type id (no BlockId, no Segment Sequence Number);
[2/2] incubator-kudu git commit: rpc: improve error messages for
overly long RPC responses
Posted by to...@apache.org.
rpc: improve error messages for overly long RPC responses
This improves the error messages to include the type name of the
PB, and also adds test coverage.
Change-Id: Id03f2e76d5929bfee33d3b2e4b55c74a97f95254
Reviewed-on: http://gerrit.cloudera.org:8080/2915
Tested-by: Kudu Jenkins
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/incubator-kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-kudu/commit/d3eb2d8f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-kudu/tree/d3eb2d8f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-kudu/diff/d3eb2d8f
Branch: refs/heads/master
Commit: d3eb2d8f44a6e2e8cc9e6c8c01955eacba4ca0f3
Parents: b688333
Author: Todd Lipcon <to...@apache.org>
Authored: Sat Apr 30 14:17:23 2016 -0700
Committer: Todd Lipcon <to...@apache.org>
Committed: Tue May 3 22:36:38 2016 +0000
----------------------------------------------------------------------
src/kudu/rpc/rpc-test-base.h | 4 ++++
src/kudu/rpc/rpc_stub-test.cc | 14 ++++++++++++++
src/kudu/rpc/rtest.proto | 1 +
src/kudu/rpc/serialization.cc | 8 ++++++--
src/kudu/rpc/transfer.cc | 14 +++++++-------
5 files changed, 32 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d3eb2d8f/src/kudu/rpc/rpc-test-base.h
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/rpc-test-base.h b/src/kudu/rpc/rpc-test-base.h
index db174eb..b0afdbe 100644
--- a/src/kudu/rpc/rpc-test-base.h
+++ b/src/kudu/rpc/rpc-test-base.h
@@ -240,6 +240,10 @@ class CalculatorService : public CalculatorServiceIf {
// marked as required. This exercises the error path of invalid responses.
context->RespondSuccess();
break;
+ case rpc_test::TestInvalidResponseRequestPB_ErrorType_RESPONSE_TOO_LARGE:
+ resp->mutable_response()->resize(FLAGS_rpc_max_message_size + 1000);
+ context->RespondSuccess();
+ break;
default:
LOG(FATAL);
}
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d3eb2d8f/src/kudu/rpc/rpc_stub-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/rpc_stub-test.cc b/src/kudu/rpc/rpc_stub-test.cc
index d23d6ee..770017a 100644
--- a/src/kudu/rpc/rpc_stub-test.cc
+++ b/src/kudu/rpc/rpc_stub-test.cc
@@ -244,6 +244,20 @@ TEST_F(RpcStubTest, TestResponseWithMissingField) {
"invalid RPC response, missing fields: response");
}
+// Test case where the server responds with a message which is larger than the maximum
+// configured RPC message size. The server should send the response, but the client
+// will reject it.
+TEST_F(RpcStubTest, TestResponseLargerThanFrameSize) {
+ CalculatorServiceProxy p(client_messenger_, server_addr_);
+
+ RpcController rpc;
+ TestInvalidResponseRequestPB req;
+ TestInvalidResponseResponsePB resp;
+ req.set_error_type(rpc_test::TestInvalidResponseRequestPB_ErrorType_RESPONSE_TOO_LARGE);
+ Status s = p.TestInvalidResponse(req, &resp, &rpc);
+ ASSERT_STR_CONTAINS(s.ToString(), "Network error: RPC frame had a length of");
+}
+
// Test sending a call which isn't implemented by the server.
TEST_F(RpcStubTest, TestCallMissingMethod) {
Proxy p(client_messenger_, server_addr_, CalculatorService::static_service_name());
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d3eb2d8f/src/kudu/rpc/rtest.proto
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/rtest.proto b/src/kudu/rpc/rtest.proto
index 076d2f6..be6fc30 100644
--- a/src/kudu/rpc/rtest.proto
+++ b/src/kudu/rpc/rtest.proto
@@ -93,6 +93,7 @@ message PanicResponsePB {}
message TestInvalidResponseRequestPB {
enum ErrorType {
MISSING_REQUIRED_FIELD = 1;
+ RESPONSE_TOO_LARGE = 2;
}
required ErrorType error_type = 1;
}
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d3eb2d8f/src/kudu/rpc/serialization.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/serialization.cc b/src/kudu/rpc/serialization.cc
index 3ad46bc..c4248cc 100644
--- a/src/kudu/rpc/serialization.cc
+++ b/src/kudu/rpc/serialization.cc
@@ -22,6 +22,7 @@
#include <google/protobuf/io/coded_stream.h>
#include "kudu/gutil/endian.h"
+#include "kudu/gutil/strings/substitute.h"
#include "kudu/gutil/stringprintf.h"
#include "kudu/rpc/constants.h"
#include "kudu/util/faststring.h"
@@ -33,6 +34,7 @@ DECLARE_int32(rpc_max_message_size);
using google::protobuf::MessageLite;
using google::protobuf::io::CodedInputStream;
using google::protobuf::io::CodedOutputStream;
+using strings::Substitute;
namespace kudu {
namespace rpc {
@@ -53,8 +55,10 @@ void SerializeMessage(const MessageLite& message, faststring* param_buf,
int total_size = size_with_delim + additional_size;
if (total_size > FLAGS_rpc_max_message_size) {
- LOG(WARNING) << "Sending too long of an RPC message (" << total_size
- << " bytes)";
+ LOG(WARNING) << Substitute("Serialized $0 ($1 bytes) is larger than the maximum configured "
+ "RPC message size ($2 bytes). "
+ "Sending anyway, but peer may reject the data.",
+ message.GetTypeName(), total_size, FLAGS_rpc_max_message_size);
}
param_buf->resize(size_with_delim);
http://git-wip-us.apache.org/repos/asf/incubator-kudu/blob/d3eb2d8f/src/kudu/rpc/transfer.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/transfer.cc b/src/kudu/rpc/transfer.cc
index a105ad6..de73f58 100644
--- a/src/kudu/rpc/transfer.cc
+++ b/src/kudu/rpc/transfer.cc
@@ -25,7 +25,6 @@
#include <glog/logging.h>
#include "kudu/gutil/endian.h"
-#include "kudu/gutil/stringprintf.h"
#include "kudu/gutil/strings/substitute.h"
#include "kudu/rpc/constants.h"
#include "kudu/rpc/messenger.h"
@@ -55,6 +54,7 @@ namespace rpc {
using std::ostringstream;
using std::set;
using std::string;
+using strings::Substitute;
#define RETURN_ON_ERROR_OR_SOCKET_NOT_READY(status) \
if (PREDICT_FALSE(!status.ok())) { \
@@ -98,13 +98,13 @@ Status InboundTransfer::ReceiveBuffer(Socket &socket) {
// add that back in.
total_length_ = NetworkByteOrder::Load32(&buf_[0]) + kMsgLengthPrefixLength;
if (total_length_ > FLAGS_rpc_max_message_size) {
- return Status::NetworkError(StringPrintf("the frame had a "
- "length of %d, but we only support messages up to %d bytes "
- "long.", total_length_, FLAGS_rpc_max_message_size));
+ return Status::NetworkError(Substitute(
+ "RPC frame had a length of $0, but we only support messages up to $1 bytes "
+ "long.", total_length_, FLAGS_rpc_max_message_size));
}
if (total_length_ <= kMsgLengthPrefixLength) {
- return Status::NetworkError(StringPrintf("the frame had a "
- "length of %d, which is invalid", total_length_));
+ return Status::NetworkError(Substitute("RPC frame had invalid length of $0",
+ total_length_));
}
buf_.resize(total_length_);
@@ -131,7 +131,7 @@ bool InboundTransfer::TransferFinished() const {
}
string InboundTransfer::StatusAsString() const {
- return strings::Substitute("$0/$1 bytes received", cur_offset_, total_length_);
+ return Substitute("$0/$1 bytes received", cur_offset_, total_length_);
}
OutboundTransfer::OutboundTransfer(int32_t call_id,