Skip to content

Commit

Permalink
Fix heartbeat packet parsing error
Browse files Browse the repository at this point in the history
Signed-off-by: tianqian.zyf <tianqian.zyf@alibaba-inc.com>
  • Loading branch information
zyfjeff committed Aug 30, 2019
1 parent 0fde42e commit 2e44467
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
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

0 comments on commit 2e44467

Please sign in to comment.