summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorvkalintiris <vasilis@netdata.cloud>2023-01-20 18:31:00 +0200
committerGitHub <noreply@github.com>2023-01-20 18:31:00 +0200
commit790ef9dfc8670527724b27d17d8decb8adb88601 (patch)
tree3919c2d5d8f2b7e7d3429d81f425394db74bdc67 /daemon
parent00e9d1c8eeac2e03e600b79a1a73c59b002855fe (diff)
Fixes required to make the agent work without crashes on MacOS (#14304)
* Bump the soft limit on open FDs to the max. On systems with a low soft-limit for open file descriptors, the agent would fail to initialize all dbengine tiers. * Iterate the right number of dbengine tiers. For whatever reason, this was causing a crash on MacOS but it was running "correctly" on Linux systems.
Diffstat (limited to 'daemon')
-rw-r--r--daemon/main.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/daemon/main.c b/daemon/main.c
index 2c10cb00bb..0d067c86a0 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -591,6 +591,32 @@ int killpid(pid_t pid) {
return ret;
}
+static void set_nofile_limit(struct rlimit *rl) {
+ // get the num files allowed
+ if(getrlimit(RLIMIT_NOFILE, rl) != 0) {
+ error("getrlimit(RLIMIT_NOFILE) failed");
+ return;
+ }
+
+ info("resources control: allowed file descriptors: soft = %zu, max = %zu",
+ (size_t) rl->rlim_cur, (size_t) rl->rlim_max);
+
+ // make the soft/hard limits equal
+ rl->rlim_cur = rl->rlim_max;
+ if (setrlimit(RLIMIT_NOFILE, rl) != 0) {
+ error("setrlimit(RLIMIT_NOFILE, { %llu, %llu }) failed", rl->rlim_cur, rl->rlim_max);
+ }
+
+ // sanity check to make sure we have enough file descriptors available to open
+ if (getrlimit(RLIMIT_NOFILE, rl) != 0) {
+ error("getrlimit(RLIMIT_NOFILE) failed");
+ return;
+ }
+
+ if (rl->rlim_cur < 1024)
+ error("Number of open file descriptors allowed for this process is too low (RLIMIT_NOFILE=%zu)", (size_t) rl->rlim_cur);
+}
+
void cancel_main_threads() {
error_log_limit_unlimited();
@@ -1883,12 +1909,7 @@ int main(int argc, char **argv) {
}
#endif /* NETDATA_INTERNAL_CHECKS */
- // get the max file limit
- if(getrlimit(RLIMIT_NOFILE, &rlimit_nofile) != 0)
- error("getrlimit(RLIMIT_NOFILE) failed");
- else
- info("resources control: allowed file descriptors: soft = %zu, max = %zu", (size_t)rlimit_nofile.rlim_cur, (size_t)rlimit_nofile.rlim_max);
-
+ set_nofile_limit(&rlimit_nofile);
delta_startup_time("become daemon");