Skip to content

Commit

Permalink
fix error request id in the dubbbo local reply (#18741)
Browse files Browse the repository at this point in the history
Signed-off-by: wbpcode <[email protected]>
  • Loading branch information
wbpcode authored Oct 27, 2021
1 parent 5d320af commit 3e9655e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void ActiveMessageEncoderFilter::continueEncoding() {
ActiveMessage::ActiveMessage(ConnectionManager& parent)
: parent_(parent), request_timer_(std::make_unique<Stats::HistogramCompletableTimespanImpl>(
parent_.stats().request_time_ms_, parent.timeSystem())),
request_id_(-1), stream_id_(parent.randomGenerator().random()),
stream_id_(parent.randomGenerator().random()),
stream_info_(parent.timeSystem(), parent_.connection().connectionInfoProviderSharedPtr()),
pending_stream_decoded_(false), local_response_sent_(false) {
parent_.stats().request_active_.inc();
Expand Down Expand Up @@ -346,7 +346,6 @@ FilterStatus ActiveMessage::applyEncoderFilters(ActiveMessageEncoderFilter* filt

void ActiveMessage::sendLocalReply(const DubboFilters::DirectResponse& response, bool end_stream) {
ASSERT(metadata_);
metadata_->setRequestId(request_id_);
parent_.sendLocalReply(*metadata_, response, end_stream);

if (end_stream) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ class ActiveMessage : public LinkedObject<ActiveMessage>,
std::list<ActiveMessageEncoderFilterPtr> encoder_filters_;
std::function<FilterStatus(DubboFilters::EncoderFilter*)> encoder_filter_action_;

int32_t request_id_;

// This value is used in the calculation of the weighted cluster.
uint64_t stream_id_;
StreamInfo::StreamInfoImpl stream_info_;
Expand Down
12 changes: 8 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 @@ -832,7 +832,7 @@ TEST_F(ConnectionManagerTest, ResponseWithUnknownSequenceID) {

TEST_F(ConnectionManagerTest, OnDataWithFilterSendsLocalReply) {
initializeFilter();
writeHessianRequestMessage(buffer_, false, false, 1);
writeHessianRequestMessage(buffer_, false, false, 233333);

config_->setupFilterChain(2, 0);
config_->expectOnDestroy();
Expand All @@ -847,8 +847,10 @@ TEST_F(ConnectionManagerTest, OnDataWithFilterSendsLocalReply) {
const std::string fake_response("mock dubbo response");
NiceMock<DubboFilters::MockDirectResponse> direct_response;
EXPECT_CALL(direct_response, encode(_, _, _))
.WillOnce(Invoke([&](MessageMetadata&, Protocol&,
.WillOnce(Invoke([&](MessageMetadata& metadata, Protocol&,
Buffer::Instance& buffer) -> DubboFilters::DirectResponse::ResponseType {
// Validate request id.
EXPECT_EQ(metadata.requestId(), 233333);
buffer.add(fake_response);
return DubboFilters::DirectResponse::ResponseType::SuccessReply;
}));
Expand Down Expand Up @@ -878,7 +880,7 @@ TEST_F(ConnectionManagerTest, OnDataWithFilterSendsLocalReply) {

TEST_F(ConnectionManagerTest, OnDataWithFilterSendsLocalErrorReply) {
initializeFilter();
writeHessianRequestMessage(buffer_, false, false, 1);
writeHessianRequestMessage(buffer_, false, false, 233334);

config_->setupFilterChain(2, 0);
config_->expectOnDestroy();
Expand All @@ -893,8 +895,10 @@ TEST_F(ConnectionManagerTest, OnDataWithFilterSendsLocalErrorReply) {
const std::string fake_response("mock dubbo response");
NiceMock<DubboFilters::MockDirectResponse> direct_response;
EXPECT_CALL(direct_response, encode(_, _, _))
.WillOnce(Invoke([&](MessageMetadata&, Protocol&,
.WillOnce(Invoke([&](MessageMetadata& metadata, Protocol&,
Buffer::Instance& buffer) -> DubboFilters::DirectResponse::ResponseType {
// Validate request id.
EXPECT_EQ(metadata.requestId(), 233334);
buffer.add(fake_response);
return DubboFilters::DirectResponse::ResponseType::ErrorReply;
}));
Expand Down

0 comments on commit 3e9655e

Please sign in to comment.