Skip to content

Commit

Permalink
fix(rpc_replay) continue when failed to init channel (#1938)
Browse files Browse the repository at this point in the history
* fix(rpc_replay) continue when failed to init channel

* check supported_connection_type

* check supported_connection_type

* check supported_connection_type

* fix lint
  • Loading branch information
ehds authored Oct 8, 2022
1 parent 5512f5c commit 5a6d99a
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tools/rpc_replay/rpc_replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <brpc/serialized_request.h>
#include <brpc/nshead_message.h>
#include <brpc/details/http_message.h>
#include "brpc/options.pb.h"
#include "info_thread.h"

DEFINE_string(dir, "", "The directory of dumped requests");
Expand Down Expand Up @@ -82,21 +83,25 @@ int ChannelGroup::Init() {
}
_chans.resize(max_protocol_size + 1);
for (size_t i = 0; i < protocols.size(); ++i) {
if (protocols[i].second.support_client() &&
protocols[i].second.support_server()) {
const brpc::ProtocolType prot = protocols[i].first;
const brpc::ProtocolType protocol_type = protocols[i].first;
const brpc::Protocol protocol = protocols[i].second;
brpc::ChannelOptions options;
options.protocol = protocol_type;
options.connection_type = FLAGS_connection_type;
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
options.max_retry = FLAGS_max_retry;
if ((options.connection_type == brpc::CONNECTION_TYPE_UNKNOWN ||
options.connection_type & protocol.supported_connection_type) &&
protocol.support_client() &&
protocol.support_server()) {
brpc::Channel* chan = new brpc::Channel;
brpc::ChannelOptions options;
options.protocol = prot;
options.connection_type = FLAGS_connection_type;
options.timeout_ms = FLAGS_timeout_ms/*milliseconds*/;
options.max_retry = FLAGS_max_retry;
if (chan->Init(FLAGS_server.c_str(), FLAGS_load_balancer.c_str(),
&options) != 0) {
LOG(ERROR) << "Fail to initialize channel";
delete chan;
return -1;
}
_chans[prot] = chan;
_chans[protocol_type] = chan;
}
}
return 0;
Expand Down

0 comments on commit 5a6d99a

Please sign in to comment.