Commit 879a247a authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

better error handling in MemoryIdler for inside jails

Summary:
/proc may be unavailable in restricted environments, which can
cause pthread_getattr_np to fail.  This diff adds checking to the return
code from that function.

Reviewed By: yfeldblum

Differential Revision: D6473789

fbshipit-source-id: de016d32f29edf8410808dfb491987692f39e768
parent 64072ab5
......@@ -25,6 +25,7 @@
#include <folly/portability/PThread.h>
#include <folly/portability/SysMman.h>
#include <folly/portability/Unistd.h>
#include <folly/synchronization/CallOnce.h>
#include <limits.h>
#include <stdio.h>
......@@ -92,13 +93,22 @@ static size_t pageSize() {
}
static void fetchStackLimits() {
int err;
pthread_attr_t attr;
pthread_getattr_np(pthread_self(), &attr);
if ((err = pthread_getattr_np(pthread_self(), &attr))) {
// some restricted environments can't access /proc
static folly::once_flag flag;
folly::call_once(flag, [err]() {
LOG(WARNING) << "pthread_getaddr_np failed errno=" << err;
});
tls_stackSize = 1;
return;
}
SCOPE_EXIT { pthread_attr_destroy(&attr); };
void* addr;
size_t rawSize;
int err;
if ((err = pthread_attr_getstack(&attr, &addr, &rawSize))) {
// unexpected, but it is better to continue in prod than do nothing
FB_LOG_EVERY_MS(ERROR, 10000) << "pthread_attr_getstack error " << err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment