[fork] Log when pthread_create fails (#32525)

There was evidence that a `pthread_create` failed in [this
comment](https://github.com/grpc/grpc/issues/31885#issuecomment-1433917201),
but without logging, we couldn't diagnose any further. This PR logs in
this case.
pull/32552/head
Richard Belleville 2 years ago committed by GitHub
parent 3de6b56ae5
commit 73bf7a364d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/core/lib/gprpp/posix/thd.cc

@ -20,6 +20,8 @@
#include <grpc/support/port_platform.h>
#include <string>
#include <grpc/support/time.h>
#ifdef GPR_POSIX_SYNC
@ -35,6 +37,7 @@
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/fork.h"
#include "src/core/lib/gprpp/strerror.h"
#include "src/core/lib/gprpp/thd.h"
namespace grpc_core {
@ -106,7 +109,7 @@ class ThreadInternalsPosix : public internal::ThreadInternalsInterface {
GPR_ASSERT(pthread_attr_setstacksize(&attr, stack_size) == 0);
}
*success = (pthread_create(
int pthread_create_err = pthread_create(
&pthread_id_, &attr,
[](void* v) -> void* {
thd_arg arg = *static_cast<thd_arg*>(v);
@ -144,11 +147,14 @@ class ThreadInternalsPosix : public internal::ThreadInternalsInterface {
}
return nullptr;
},
info) == 0);
info);
*success = (pthread_create_err == 0);
GPR_ASSERT(pthread_attr_destroy(&attr) == 0);
if (!(*success)) {
gpr_log(GPR_ERROR, "pthread_create failed: %s",
StrError(pthread_create_err).c_str());
// don't use gpr_free, as this was allocated using malloc (see above)
free(info);
if (options.tracked()) {

Loading…
Cancel
Save