2704: h2o: config: bug-fix: max-connections configuration value should not exceed RLIMIT_NOFILE
@@ -3440,10 +3440,13 @@ int main(int argc, char **argv)
conf.error_log = NULL;
}
- { /* raise RLIMIT_NOFILE */
- struct rlimit limit;
+ {
+ struct rlimit limit = { 0 };
+
if (getrlimit(RLIMIT_NOFILE, &limit) == 0) {
+ /* raise RLIMIT_NOFILE */
limit.rlim_cur = limit.rlim_max;
+
if (setrlimit(RLIMIT_NOFILE, &limit) == 0
#ifdef __APPLE__
|| (limit.rlim_cur = OPEN_MAX, setrlimit(RLIMIT_NOFILE, &limit)) == 0
@@ -3452,6 +3455,16 @@ int main(int argc, char **argv)
fprintf(stderr, "[INFO] raised RLIMIT_NOFILE to %d\n", (int)limit.rlim_cur);
}
}
+
+ if (conf.max_connections > (int)limit.rlim_cur) {
+ fprintf(stderr,
+ "[FATAL] The 'max-connections'=[%d] configuration value "
+ "should not exceed the file descriptor limit of "
+ "the process 'RLIMIT_NOFILE'=[%lu]\n",
+ conf.max_connections,
+ limit.rlim_cur);
+ return EX_CONFIG;
+ }
}
setup_signal_handlers();
