Update to set 'num-threads' instead of setting 'nofiles' limit via 'prlimit'
@@ -178,7 +178,6 @@ sub spawn_server {
die "fork failed:$!"
unless defined $pid;
if ($pid != 0) {
- system("sudo prlimit --nofile=1048576:1048576 --pid $pid");
print STDERR "spawning $args{argv}->[0]... ";
if ($args{is_ready}) {
while (1) {
@@ -272,6 +271,13 @@ EOT
sub spawn_h2o_raw {
my ($conf, $check_ports, $opts) = @_;
+ # By default, h2o will launch as many threads as there are CPU cores on the
+ # host, unless 'num-threads' is specified. This results in the process
+ # running out of file descriptors, if the 'nofiles' limit is low and the
+ # host has a large number of CPU cores. So make sure the number of threads
+ # is bound.
+ $conf = "num-threads: 2\n$conf" unless $conf =~ /^num-threads:/m;
+
my ($conffh, $conffn) = tempfile(UNLINK => 1);
print $conffh $conf;
