Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix heartbeat packet parsing error #8103

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions source/extensions/filters/network/dubbo_proxy/decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ DecoderStateMachine::onDecodeStreamHeader(Buffer::Instance& buffer) {
return {ProtocolState::WaitForData};
}

// The heartbeat message has no body.
auto context = ret.first;
if (metadata->message_type() == MessageType::HeartbeatRequest ||
metadata->message_type() == MessageType::HeartbeatResponse) {
if (buffer.length() < (context->header_size() + context->body_size())) {
ENVOY_LOG(debug, "dubbo decoder: need more data for {} protocol heartbeat", protocol_.name());
return {ProtocolState::WaitForData};
}

ENVOY_LOG(debug, "dubbo decoder: this is the {} heartbeat message", protocol_.name());
buffer.drain(context->header_size());
buffer.drain(context->header_size() + context->body_size());
delegate_.onHeartbeat(metadata);
return {ProtocolState::Done};
}
Expand Down
11 changes: 7 additions & 4 deletions test/extensions/filters/network/dubbo_proxy/conn_manager_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ class ConnectionManagerTest : public testing::Test {
buffer.add(static_cast<void*>(&msg_type), 1);
buffer.add(std::string{0x14});
addInt64(buffer, request_id); // Request Id
buffer.add(std::string{0x00, 0x00, 0x00, 0x00}); // Body Length
buffer.add(std::string{0x00, 0x00, 0x00, 0x01}); // Body Length
buffer.add(std::string{0x01}); // Body
}

NiceMock<Server::Configuration::MockFactoryContext> factory_context_;
Expand Down Expand Up @@ -377,6 +378,7 @@ TEST_F(ConnectionManagerTest, OnDataHandlesHeartbeatEvent) {
}));

EXPECT_EQ(conn_manager_->onData(buffer_, false), Network::FilterStatus::StopIteration);
EXPECT_EQ(0U, buffer_.length());
filter_callbacks_.connection_.dispatcher_.clearDeferredDeleteList();

EXPECT_EQ(0U, store_.counter("test.request").value());
Expand Down Expand Up @@ -1156,8 +1158,7 @@ TEST_F(ConnectionManagerTest, PendingMessageEnd) {
EXPECT_EQ(1U, store_.gauge("test.request_active", Stats::Gauge::ImportMode::Accumulate).value());
}

// TODO(alyssawilk) update.
TEST_F(ConnectionManagerTest, DEPRECATED_FEATURE_TEST(Routing)) {
TEST_F(ConnectionManagerTest, Routing) {
const std::string yaml = R"EOF(
stat_prefix: test
protocol_type: Dubbo
Expand All @@ -1169,7 +1170,9 @@ serialization_type: Hessian2
- match:
method:
name:
regex: "(.*?)"
safe_regex:
google_re2: {}
regex: "(.*?)"
route:
cluster: user_service_dubbo_server
)EOF";
Expand Down