diff --git a/src/postgres/src/backend/postmaster/postmaster.c b/src/postgres/src/backend/postmaster/postmaster.c index a50aff56632d..6456f408905c 100644 --- a/src/postgres/src/backend/postmaster/postmaster.c +++ b/src/postgres/src/backend/postmaster/postmaster.c @@ -944,6 +944,19 @@ PostmasterMain(int argc, char *argv[]) } YBReportIfYugaByteEnabled(); +#ifdef __APPLE__ + if (YBIsEnabledInPostgresEnvVar()) { + /* + * Resolve local hostname to initialize macOS network libraries. If we + * don't do this, there might be a lot of segmentation faults in + * PostgreSQL backend processes in tests on macOS (especially debug + * mode). + * + * See https://github.com/yugabyte/yugabyte-db/issues/2509 for details. + */ + YBCResolveHostname(); + } +#endif /* * Create lockfile for data directory. diff --git a/src/yb/common/ybc_util.cc b/src/yb/common/ybc_util.cc index e51faf665b71..1a71e6eaac3d 100644 --- a/src/yb/common/ybc_util.cc +++ b/src/yb/common/ybc_util.cc @@ -30,6 +30,8 @@ #include "yb/util/status.h" #include "yb/util/version_info.h" +#include "yb/util/net/net_util.h" + #include "yb/gutil/stringprintf.h" using std::string; @@ -258,6 +260,15 @@ const char* YBCGetStackTrace() { return YBCPAllocStdString(yb::GetStackTrace()); } +void YBCResolveHostname() { + string fqdn; + auto status = GetFQDN(&fqdn); + if (!status.ok()) { + LOG(WARNING) << "Failed to get fully qualified domain name of the local hostname: " + << status; + } +} + } // extern "C" } // namespace yb diff --git a/src/yb/common/ybc_util.h b/src/yb/common/ybc_util.h index a15b2004bd03..1e7a1bda49d6 100644 --- a/src/yb/common/ybc_util.h +++ b/src/yb/common/ybc_util.h @@ -42,6 +42,8 @@ const char* YBCStatusCodeAsCString(YBCStatus s); bool YBCIsRestartReadError(uint16_t txn_errcode); +void YBCResolveHostname(); + #define CHECKED_YBCSTATUS __attribute__ ((warn_unused_result)) YBCStatus typedef void* (*YBCPAllocFn)(size_t size);