Welcome! Log In Create A New Profile

Advanced

fpm_unix_init_main(), line 284: getrlimit(nofile)

Posted by wolfenstock 
fpm_unix_init_main(), line 284: getrlimit(nofile)
July 28, 2009 02:23PM
I am keep getting these type of errors even though i set php-fpm.conf much higher :

[NOTICE] fpm_unix_init_main(), line 284: getrlimit(nofile): max:1024, cur:1024
[ERROR] fpm_unix_init_child(), line 168: setrlimit(RLIMIT_NOFILE) failed: Invalid argument (22)"

I can confirm the hard/soft limit is much higher for centos os. I can confirm the user running as is much higherhigher but no matter what it still gives this erro.
Where do I change this besides the php-fpm.conf file to get it to recognize the rlimit?

Please help. Thank you.
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
July 28, 2009 06:50PM
I got these kind of warnings with nginx too...

So your /etc/security/limits.conf has the right stuff setup?

The relevant line should be this inside of each "pool" section

<value name="rlimit_files">1024</value>



On Tue, Jul 28, 2009 at 11:23 AM, wolfenstock<nginx-forum@nginx.us> wrote:
>
> I am keep getting these type of errors even though i set php-fpm.conf much higher  :
>
>  fpm_unix_init_main(), line 284: getrlimit(nofile): max:1024, cur:1024
>  fpm_unix_init_child(), line 168: setrlimit(RLIMIT_NOFILE) failed: Invalid argument (22)"
>
> I can confirm the hard/soft limit is much higher for centos os. I can confirm the user running as is much higherhigher but no matter what it still gives this erro.
> Where do I change this besides the php-fpm.conf file to get it to recognize the rlimit?
>
> Please help.  Thank you.
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?3,4539,4539#msg-4539
>
>
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 09, 2010 07:21PM
# ulimit -n
1024
if php-fpm.conf set <value name="rlimit_files">[b]4096[/b]</value> ,php-fpm.log will display error
[ERROR] fpm_unix_init_child(), line 168: setrlimit(RLIMIT_NOFILE) failed: Invalid argument (22)"



#vi /etc/security/limits.conf
add
[b]* soft nofile 4096
* hard nofile 4096[/b]

# vi /etc/sysctl.conf
add
fs.file-max=4096

reboot will be ok
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 09, 2010 07:28PM
That is really annoying you have to do it in both limits.conf -and- sysctl.conf

That's probably been the missing thing in my config - some of my
machines whine about the rlimit stuff and some don't. I bet the
machines that don't have all of my extra sysctl.conf tweaks and the
ones that whine don't :)


On Sat, Jan 9, 2010 at 4:21 PM, lnxa <nginx-forum@nginx.us> wrote:
> # ulimit -n
> 1024
> if php-fpm.conf set 4096 ,php-fpm.log will display error
>  fpm_unix_init_child(), line 168: setrlimit(RLIMIT_NOFILE) failed: Invalid argument (22)"
>
>
>
> #vi /etc/security/limits.conf
> add
> *        soft    nofile  4096
> *        hard    nofile  4096
>
> # vi /etc/sysctl.conf
> add
> fs.file-max=4096
>
> reboot will be  ok
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?3,4539,39268#msg-39268
>
>
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 09, 2010 07:31PM
this was an old thread but thankyou for the response. You could also set the ulimit in the startup script. I would suggest that setting be commented in the config file so there wasn't any confusion but since it's been over 9months I guess only a few people would change that setting.
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 09, 2010 07:34PM
i do a ulimit -n 131072 in /etc/profile but it whines when i login to
any shell :)

i didn't want to alter the default init script for nginx or php-fpm so
i was looking to alter it somewhere else, i also wanted to make sure
any user that nginx or php-fpm might be running as would inherit it.

i'll have to test this out next time i reboot.

On Sat, Jan 9, 2010 at 4:31 PM, wolfenstock <nginx-forum@nginx.us> wrote:
> this was an old thread but thankyou for the response.  You could also set the ulimit in the startup script.  I would suggest that setting be commented in the config file so there wasn't any confusion but since it's been over 9months I guess only a few people would change that setting.
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?3,4539,39273#msg-39273
>
>
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 09, 2010 07:36PM
mike. common mistake is to assume the profile setting will set the ulimit for startup scripts. This is not the case.
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 09, 2010 07:52PM
It does work when I am restarting from my shell though. Your
suggestion is to put it inside of php-fpm and nginx init scripts? In
theory it shouldn't be needed if limits.conf and sysctl.conf are
defined and it's configured inside of php-fpm and nginx as they will
ask for that rlimit and it will not reject it. So really if I put it
in those I can remove it from /etc/profile then anyway. I think I'm
talking out loud. That makes sense right? :)

On Jan 9, 2010, at 4:36 PM, "wolfenstock" <nginx-forum@nginx.us> wrote:

> mike. common mistake is to assume the profile setting will set the
> ulimit for startup scripts. This is not the case.
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?3,4539,39275#msg-39275
>
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 09, 2010 07:59PM
I apologize if I wasn't clear. You would not need it in the startup scripts if you set higher security limits. However if you merely edit the profile ulimit; that setting has no effect on php-fpm or nginx startup.
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 11, 2010 02:04AM
Oddly enough, I just set this up in /etc/security/limits.conf and in
/etc/sysctl.conf

Rebooted, wouldn't take.

Even added ulimit -n 131072 to /etc/profile and /etc/rc.local - just for kicks.

Still won't take.

2010/01/10 23:01:25 [notice] 1120#0: getrlimit(RLIMIT_NOFILE): 1024:1024

Jan 10 23:01:27.546913 [WARNING] fpm_stdio_child_said(), line 167:
child 1219 (pool www-data) said into stderr: "Jan 10 23:01:27.546403
[ERROR] fpm_unix_init_child(), line 168: setrlimit(RLIMIT_NOFILE)
failed: Invalid argument (22)"


Running Ubuntu Karmic... this is weird. I can't figure out why on some
machines it works and some it won't.



On Sat, Jan 9, 2010 at 4:59 PM, wolfenstock <nginx-forum@nginx.us> wrote:
> I apologize if I wasn't clear.  You would not need it in the startup scripts if you set higher security limits.  However if you merely edit the profile ulimit; that setting has no effect on php-fpm or nginx startup.
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?3,4539,39282#msg-39282
>
>
Momchil Ivanov
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 11, 2010 07:14PM
На понеделник 11 януари 2010 09:02:43 Michael Shadle написа:
> Oddly enough, I just set this up in /etc/security/limits.conf and in
> /etc/sysctl.conf
>
> Rebooted, wouldn't take.
>
> Even added ulimit -n 131072 to /etc/profile and /etc/rc.local - just for
> kicks.
>
> Still won't take.
>
> 2010/01/10 23:01:25 [notice] 1120#0: getrlimit(RLIMIT_NOFILE): 1024:1024
>
> Jan 10 23:01:27.546913 [WARNING] fpm_stdio_child_said(), line 167:
> child 1219 (pool www-data) said into stderr: "Jan 10 23:01:27.546403
> [ERROR] fpm_unix_init_child(), line 168: setrlimit(RLIMIT_NOFILE)
> failed: Invalid argument (22)"
>
>
> Running Ubuntu Karmic... this is weird. I can't figure out why on some
> machines it works and some it won't.
>
> On Sat, Jan 9, 2010 at 4:59 PM, wolfenstock <nginx-forum@nginx.us> wrote:
> > I apologize if I wasn't clear. You would not need it in the startup
> > scripts if you set higher security limits. However if you merely edit
> > the profile ulimit; that setting has no effect on php-fpm or nginx
> > startup.
> >
> > Posted at Nginx Forum:
> > http://forum.nginx.org/read.php?3,4539,39282#msg-39282
>

I'm using [1] and the code in sapi/cgi/fpm/fpm_unix.c says:

160 if (wp->config->rlimit_files) {
161 struct rlimit r;
162
163 getrlimit(RLIMIT_NOFILE, &r);
164
165 r.rlim_cur = (rlim_t) wp->config->rlimit_files;
166
167 if (0 > setrlimit(RLIMIT_NOFILE, &r)) {
168 zlog(ZLOG_STUFF, ZLOG_SYSERROR,
"setrlimit(RLIMIT_NOFILE) failed");
169 }
170 }

Which reads as: if there is a setting in the fpm conf, get that and try to set
it. The linux manpage of setrlimit(2) says it returns:

EFAULT rlim points outside the accessible address space.

EINVAL resource is not valid; or, for setrlimit(): rlim->rlim_cur was
greater than rlim->rlim_max.

EPERM An unprivileged process tried to use setrlimit() to increase
a soft or hard limit above the
current hard limit; the CAP_SYS_RESOURCE capability is required
to do this. Or, the process
tried to use setrlimit() to increase the soft or hard
RLIMIT_NOFILE limit above the current
kernel maximum (NR_OPEN).

on FreeBSD it should return:

[EFAULT] The address specified for rlp is invalid.

[EPERM] The limit specified to setrlimit() would have raised
the maximum limit value, and the caller is not the
super‐user.

So if you are running with root on gnu/linux, you are most probably getting
the EINVAL error in which case the code might be fixed to try increasing
rlimit_max. If you haven't specified that setting in your fpm conf, the values
are inherited from the process that executed fpm - most probably your shell,
so you need to set them there.

btw ulimit is a bash command, so if your shell is not bash, you have to look
up what command you should use.

on gnu/linux: don't rely on /etc/security/limits.conf since it's supposed to
be user specific, you are most probably running fpm with root and you don't
know if your shell doesn't set it to some default sane value (1024?) in order
to protect you from taking the system down, since shells are made to interact
with people and people do make mistakes :)

1: http://php-fpm.org/downloads/php-5.2.10-fpm-0.5.11.diff.gz

Momchil
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 11, 2010 07:40PM
On Mon, Jan 11, 2010 at 4:12 PM, Momchil Ivanov <slogster@gmail.com> wrote:

> Which reads as: if there is a setting in the fpm conf, get that and try to set
> it.  The linux manpage of setrlimit(2) says it returns:


> So if you are running with root on gnu/linux, you are most probably getting
> the EINVAL error in which case the code might be fixed to try increasing
> rlimit_max. If you haven't specified that setting in your fpm conf, the values
> are inherited from the process that executed fpm - most probably your shell,
> so you need to set them there.

I've got rlimit_files set to 131072 in php-fpm.conf, and in nginx.conf...

> btw ulimit is a bash command, so if your shell is not bash, you have to look
> up what command you should use.

that is a good point; the startup scripts could be using sh, not bash.
However it looks like "sh" still supports ulimit, just not very
advanced.

> on gnu/linux: don't rely on /etc/security/limits.conf since it's supposed to
> be user specific, you are most probably running fpm with root and you don't
> know if your shell doesn't set it to some default sane value (1024?) in order
> to protect you from taking the system down, since shells are made to interact
> with people and people do make mistakes :)

These systems only have /bin/false users... I'm fine with setting
system-wide limits. :)
Momchil Ivanov
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 12, 2010 06:22AM
На вторник 12 януари 2010 01:37:51 Michael Shadle написа:
> On Mon, Jan 11, 2010 at 4:12 PM, Momchil Ivanov <slogster@gmail.com> wrote:
> > Which reads as: if there is a setting in the fpm conf, get that and try
> > to set it. The linux manpage of setrlimit(2) says it returns:
> >
> >
> > So if you are running with root on gnu/linux, you are most probably
> > getting the EINVAL error in which case the code might be fixed to try
> > increasing rlimit_max. If you haven't specified that setting in your fpm
> > conf, the values are inherited from the process that executed fpm - most
> > probably your shell, so you need to set them there.
>
> I've got rlimit_files set to 131072 in php-fpm.conf, and in nginx.conf...

if you are running it with root, your shell has set rlimit_max greater than
that value, therefore you might try the following in sapi/cgi/fpm/fpm_unix.c
add :
r.rlim_max = (rlim_t) wp->config->rlimit_files;
after:
165 r.rlim_cur = (rlim_t) wp->config->rlimit_files;

> > btw ulimit is a bash command, so if your shell is not bash, you have to
> > look up what command you should use.
>
> that is a good point; the startup scripts could be using sh, not bash.
> However it looks like "sh" still supports ulimit, just not very
> advanced.

most gnu/linux distros have /bin/sh symlinked to /bin/bash :)
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 14, 2010 06:00PM
On Tue, Jan 12, 2010 at 3:20 AM, Momchil Ivanov <slogster@gmail.com> wrote:

> if you are running it with root, your shell has set rlimit_max greater than
> that value, therefore you might try the following in sapi/cgi/fpm/fpm_unix.c
> add :
>                        r.rlim_max = (rlim_t) wp->config->rlimit_files;
> after:
> 165                 r.rlim_cur = (rlim_t) wp->config->rlimit_files;

My main concern isn't actually restarting it as root manually when I
login because it appears I can do that without an issue because it
will inherit the ulimit I have defined. I want it to work on startup /
non-interactive shells.

> most gnu/linux distros have /bin/sh symlinked to /bin/bash :)

mine (Ubuntu Karmic) has a distinct difference between the two.
Actually it looks like "sh" is symlinked to "dash" ... still a very
basic shell though.
Momchil Ivanov
Re: fpm_unix_init_main(), line 284: getrlimit(nofile)
January 14, 2010 06:40PM
На четвъртък 14 януари 2010 23:58:41 Michael Shadle написа:
> On Tue, Jan 12, 2010 at 3:20 AM, Momchil Ivanov <slogster@gmail.com> wrote:
> > if you are running it with root, your shell has set rlimit_max greater
> > than that value, therefore you might try the following in
> > sapi/cgi/fpm/fpm_unix.c add :
> > r.rlim_max = (rlim_t) wp->config->rlimit_files;
> > after:
> > 165 r.rlim_cur = (rlim_t) wp->config->rlimit_files;
>
> My main concern isn't actually restarting it as root manually when I
> login because it appears I can do that without an issue because it
> will inherit the ulimit I have defined. I want it to work on startup /
> non-interactive shells.

That should fix your startup problem if your startup script runs fpm with
root.

Momchil
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 303
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready