'c++ grpc call with SslCredentials makes coredump always

thanks in advance.

I'm trying to make client program for grpc comm in ros(melodic)system. but when i call any rpc method with sslcredentials, it always makes coredump.

my env is below

  • ubuntu / c++
  • ros melodic
  • with InsecureChannelCredentials, it works fine
  • with sslCredention, it makes always coredump
  • testing with modified sample codes(it's running on normal ubuntu system not ros), works fine.

Actually, I expect ssl handshake fail as a result of program. but i do not know why it makes crash. I guess it is related with program launch environment(this program is for ros) but i'm not sure.

if you guys know why, please let me know.

here is my code

 HelloRequest request;
  request.set_name("test");
  DirUtils::readWholeFile("roots.pem", cacert);
  HelloReply reply;
  ClientContext context;

  grpc::SslCredentialsOptions ssl_opts = {cacert.c_str(), "", ""};
  ssl_opts.pem_root_certs = cacert.c_str();
  auto channel_creds = grpc::SslCredentials(ssl_opts);

#if 1
  auto channel = grpc::CreateChannel("localhost:50051", channel_creds);
#else
  auto channel = grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials());
#endif

  std::unique_ptr<Greeter::Stub> stub(Greeter::NewStub(channel));
  CLOGE("runrunrun");
  grpc::Status status = stub->SayHello(&context, request, &reply);
  if (status.ok()) {
    CLOGE("%s", reply.message().c_str());
  } else {
    std::cout << status.error_code() << ": " << status.error_message() << std::endl;
    CLOGE("RPC failed");
  }

Below is grpc trace with GRPC_TRACE=round_robin,connectivity_state,pick_first dns_resolver subchannel subchannel_pool

with SslCredention

[ INFO] [1647838520.766193359]: [GRPC][CloudRoboTaxiProxy] : 
D0321 13:55:20.766466283   10705 ev_posix.cc:172]            Using polling engine: epollex
D0321 13:55:20.766535088   10705 lb_policy_registry.cc:42]   registering LB policy factory for "grpclb"
D0321 13:55:20.766546645   10705 lb_policy_registry.cc:42]   registering LB policy factory for "priority_experimental"
D0321 13:55:20.766551896   10705 lb_policy_registry.cc:42]   registering LB policy factory for "weighted_target_experimental"
D0321 13:55:20.766556531   10705 lb_policy_registry.cc:42]   registering LB policy factory for "pick_first"
D0321 13:55:20.766560778   10705 lb_policy_registry.cc:42]   registering LB policy factory for "round_robin"
D0321 13:55:20.766565164   10705 lb_policy_registry.cc:42]   registering LB policy factory for "ring_hash_experimental"
D0321 13:55:20.766572233   10705 dns_resolver_ares.cc:495]   Using ares dns resolver
D0321 13:55:20.766600439   10705 certificate_provider_registry.cc:33] registering certificate provider factory for "file_watcher"
D0321 13:55:20.766608461   10705 lb_policy_registry.cc:42]   registering LB policy factory for "cds_experimental"
D0321 13:55:20.766615145   10705 lb_policy_registry.cc:42]   registering LB policy factory for "xds_cluster_impl_experimental"
D0321 13:55:20.766620460   10705 lb_policy_registry.cc:42]   registering LB policy factory for "xds_cluster_resolver_experimental"
D0321 13:55:20.766625384   10705 lb_policy_registry.cc:42]   registering LB policy factory for "xds_cluster_manager_experimental"
[ERROR] [1647838520.766839781]: [GRPC][CloudRoboTaxiProxy] : RUNRUNRUN
I0321 13:55:20.766971552   10705 connectivity_state.cc:182]  ConnectivityStateTracker client_channel[0x56429ac907d8]: get current state: IDLE
I0321 13:55:20.766995225   10705 connectivity_state.cc:182]  ConnectivityStateTracker client_channel[0x56429ac907d8]: get current state: IDLE
I0321 13:55:20.767014411   10705 connectivity_state.cc:159]  ConnectivityStateTracker client_channel[0x56429ac907d8]: IDLE -> CONNECTING (started resolving, OK)
I0321 13:55:20.830628662   10705 pick_first.cc:144]          Pick First 0x56429aca6a70 created.
I0321 13:55:20.830652683   10705 pick_first.cc:261]          Pick First 0x56429aca6a70 received update with 1 addresses
I0321 13:55:20.830661559   10705 subchannel_list.h:363]      [pick_first 0x56429aca6a70] Creating subchannel list 0x56429aca6de0 for 1 subchannels
Segmentation fault (core dumped)

with InsecureCredentials

[ INFO] [1647838665.719818173]: [GRPC][CloudRoboTaxiProxy] : 
D0321 13:57:45.720068078   18636 ev_posix.cc:172]            Using polling engine: epollex
D0321 13:57:45.720134657   18636 lb_policy_registry.cc:42]   registering LB policy factory for "grpclb"
D0321 13:57:45.720145342   18636 lb_policy_registry.cc:42]   registering LB policy factory for "priority_experimental"
D0321 13:57:45.720150278   18636 lb_policy_registry.cc:42]   registering LB policy factory for "weighted_target_experimental"
D0321 13:57:45.720154793   18636 lb_policy_registry.cc:42]   registering LB policy factory for "pick_first"
D0321 13:57:45.720158925   18636 lb_policy_registry.cc:42]   registering LB policy factory for "round_robin"
D0321 13:57:45.720163193   18636 lb_policy_registry.cc:42]   registering LB policy factory for "ring_hash_experimental"
D0321 13:57:45.720170070   18636 dns_resolver_ares.cc:495]   Using ares dns resolver
D0321 13:57:45.720196517   18636 certificate_provider_registry.cc:33] registering certificate provider factory for "file_watcher"
D0321 13:57:45.720203835   18636 lb_policy_registry.cc:42]   registering LB policy factory for "cds_experimental"
D0321 13:57:45.720209495   18636 lb_policy_registry.cc:42]   registering LB policy factory for "xds_cluster_impl_experimental"
D0321 13:57:45.720214363   18636 lb_policy_registry.cc:42]   registering LB policy factory for "xds_cluster_resolver_experimental"
D0321 13:57:45.720219090   18636 lb_policy_registry.cc:42]   registering LB policy factory for "xds_cluster_manager_experimental"
[ERROR] [1647838665.720435529]: [GRPC][CloudRoboTaxiProxy] : runrunrun
I0321 13:57:45.720566714   18636 connectivity_state.cc:182]  ConnectivityStateTracker client_channel[0x564b8c974788]: get current state: IDLE
I0321 13:57:45.720589783   18636 connectivity_state.cc:182]  ConnectivityStateTracker client_channel[0x564b8c974788]: get current state: IDLE
I0321 13:57:45.720607804   18636 connectivity_state.cc:159]  ConnectivityStateTracker client_channel[0x564b8c974788]: IDLE -> CONNECTING (started resolving, OK)
I0321 13:57:51.813909546   18636 pick_first.cc:144]          Pick First 0x564b8c98ab70 created.
I0321 13:57:51.813938340   18636 pick_first.cc:261]          Pick First 0x564b8c98ab70 received update with 1 addresses
I0321 13:57:51.813947230   18636 subchannel_list.h:363]      [pick_first 0x564b8c98ab70] Creating subchannel list 0x564b8c98ae20 for 1 subchannels
I0321 13:57:51.813989918   18636 subchannel_list.h:383]      [pick_first 0x564b8c98ab70] subchannel list 0x564b8c98ae20 index 0: Created subchannel 0x564b8c6321a0 for address 127.0.0.1:50051 args={}
I0321 13:57:51.814000974   18636 subchannel_list.h:310]      [pick_first 0x564b8c98ab70] subchannel list 0x564b8c98ae20 index 0 of 1 (subchannel 0x564b8c6321a0): starting watch (from IDLE)
I0321 13:57:51.814004907   18636 ref_counted.h:86]           SubchannelList:0x564b8c98ae28 /home/omega/tools/grpc/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h:319 ref 1 -> 2 Watcher
I0321 13:57:51.814114063   18636 connectivity_state.cc:182]  ConnectivityStateTracker client_channel[0x564b8c974788]: get current state: CONNECTING
I0321 13:57:51.814149960   18636 subchannel_list.h:243]      [pick_first 0x564b8c98ab70] subchannel list 0x564b8c98ae20 index 0 of 1 (subchannel 0x564b8c6321a0): connectivity changed: state=CONNECTING, shutting_down=0, pending_watcher=0x564b8c98b0c0
I0321 13:57:51.814507743   18636 subchannel_list.h:243]      [pick_first 0x564b8c98ab70] subchannel list 0x564b8c98ae20 index 0 of 1 (subchannel 0x564b8c6321a0): connectivity changed: state=READY, shutting_down=0, pending_watcher=0x564b8c98b0c0
I0321 13:57:51.814516269   18636 pick_first.cc:457]          Pick First 0x564b8c98ab70 selected subchannel 0x564b8c6321a0
I0321 13:57:51.814521702   18636 connectivity_state.cc:159]  ConnectivityStateTracker client_channel[0x564b8c974788]: CONNECTING -> READY (helper, OK)
I0321 13:57:51.814551635   18636 connectivity_state.cc:122]  ConnectivityStateTracker client_transport[0x7fa2900025d8]: add watcher 0x564b8c97c450
[ERROR] [1647838671.815124034]: [GRPC][CloudRoboTaxiProxy] : Hello test
I0321 13:57:51.815213570   18636 pick_first.cc:158]          Pick First 0x564b8c98ab70 Shutting down
I0321 13:57:51.815222628   18636 subchannel_list.h:404]      [pick_first 0x564b8c98ab70] Shutting down subchannel_list 0x564b8c98ae20
I0321 13:57:51.815259904   18636 subchannel_list.h:330]      [pick_first 0x564b8c98ab70] subchannel list 0x564b8c98ae20 index 0 of 1 (subchannel 0x564b8c6321a0): canceling connectivity watch (shutdown)
I0321 13:57:51.815267166   18636 ref_counted.h:182]          SubchannelList:0x564b8c98ae28 /home/omega/tools/grpc/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h:146 unref 2 -> 1 Watcher dtor
I0321 13:57:51.815275667   18636 subchannel_list.h:287]      [pick_first 0x564b8c98ab70] subchannel list 0x564b8c98ae20 index 0 of 1 (subchannel 0x564b8c6321a0): unreffing subchannel (shutdown)
I0321 13:57:51.815298707   18636 ref_counted.h:182]          SubchannelList:0x564b8c98ae28 /home/omega/tools/grpc/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h:200 unref 1 -> 0 shutdown
I0321 13:57:51.815323065   18636 subchannel_list.h:396]      [pick_first 0x564b8c98ab70] Destroying subchannel_list 0x564b8c98ae20
I0321 13:57:51.815328477   18636 pick_first.cc:150]          Destroying Pick First 0x564b8c98ab70
I0321 13:57:51.815342666   18636 connectivity_state.cc:159]  ConnectivityStateTracker client_channel[0x564b8c974788]: READY -> SHUTDOWN (shutdown from API, OK)
I0321 13:57:51.815388688   18636 connectivity_state.cc:159]  ConnectivityStateTracker client_transport[0x7fa2900025d8]: READY -> SHUTDOWN (close_transport, OK)
I0321 13:57:51.815397929   18636 connectivity_state.cc:167]  ConnectivityStateTracker client_transport[0x7fa2900025d8]: notifying watcher 0x564b8c97c450: READY -> SHUTDOWN
I0321 13:57:51.815417452   18636 connectivity_state.cc:79]   watcher 0x564b8c97c450: delivering async notification for SHUTDOWN (OK)
D0321 13:57:51.815500746   18636 init.cc:179]                grpc_shutdown starts clean-up now
[ INFO] [1647838671.815908345]: [GRPC][~CloudRoboTaxiProxy] : 

if you needs more information, please tell me



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source