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

多provider情况下Heartbeat会core在inet_ntoa #57

Open
Lohnwave opened this issue Jul 15, 2024 · 1 comment
Open

多provider情况下Heartbeat会core在inet_ntoa #57

Lohnwave opened this issue Jul 15, 2024 · 1 comment

Comments

@Lohnwave
Copy link

我们创建了多个ProviderApi来将实例注册到多个不同的名字服务上。但在运行中,会随机出现core在心跳时解析host上。
看到TryLookup 中使用了非线程安全的inet_ntoa。为什么不适用线程安全的inet_ntop了?
std::string target_address = inet_ntoa(*(struct in_addr*)host->h_addr_list[0]);

(gdb) bt
#0 0x0000000001e08b8c in polaris::grpc::TryLookup (address=...) at polaris/network/grpc/http2.cpp:425
#1 polaris::grpc::Http2Client::ConnectTo(std::string const&, int) () at polaris/network/grpc/http2.cpp:455
#2 0x0000000001dbbe54 in polaris::grpc::GrpcClient::ConnectTo (port=, host=..., this=0x7fa36a607c80) at polaris/network/grpc/client.h:192
#3 polaris::BlockRequest::PrepareClient() () at polaris/plugin/server_connector/grpc_server_connector.cpp:972
#4 0x0000000001dbcdde in polaris::GrpcServerConnector::InstanceHeartbeat (this=, req=..., timeout_ms=)
at polaris/plugin/server_connector/grpc_server_connector.cpp:762
#5 0x0000000001e0367b in polaris::ProviderApi::Heartbeat(polaris::InstanceHeartbeatRequest const&) () at polaris/provider/api.cpp:196
#6 0x0000000001d84e90 in gxl_utils::PolarisWrapper::KeepHealth() () at gxl-utils/polaris/polaris_wrapper.cc:199
#7 0x00000000020f65af in execute_native_thread_routine ()
#8 0x00007fc0de8e2e65 in ?? ()
#9 0x0000000000000000 in ?? ()

@Lohnwave
Copy link
Author

对gethostbyname方法加锁可以解决这个问题,或者换成线程安全的getaddrinfo

static std::string TryLookup(const std::string& address) {
  // ..
  g_mt.lock();
  struct hostent* host = gethostbyname(address.c_str());
  g_mt.unlock();
  // ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant