Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2010-03

"Unable to open file" on Linux randomly in a CGI application when using templates

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ABorka

Hi,

I have a CGI application with a datamodule that is using templates to generate the response pages (accessing a MySQL database through ZEOS). Every once in a while, I'm getting an "Unable to open file" exception that points to one of the templates the website is using.

What could be the problem? The fcl-web template handling is opening the template files with the "fmOpenRead" flag so there should not be any problem, no matter how many requests arrive to the web server at the same time.

Could this be some kind of Linux setting? There is nothing in the system logs. (Debian 5.04 /Lenny/, Apache 2.2.9)

Any ideas or help is appreciated to help to find this problem.

Thanks,

AB

Reply by email

Jonas Maebe
to ABorka
ABorka wrote
I have a CGI application with a datamodule that is using templates to generate the response pages (accessing a MySQL database through ZEOS). Every once in a while, I'm getting an "Unable to open file" exception that points to one of the templates the website is using. What could be the problem?

Maybe you run out of file handles?

Jonas

Reply by email

ABorka
to Jonas Maebe

If that is the case, shouldn't something be in the syslog or some other log? Is there any way I can check this for sure like last system error string or something?
The exception message only says that "Unable to open file <filepath_filename>".

I checked the /proc/sys/fs/file-max and it shows 294692

For now, I'm retrying again the page generation if an exception happens. So far seems to be working, but will need more time to really see. It was rare to happen.

AB

Jonas Maebe wrote 12 lines
On 14 Mar 2010, at 23:39, ABorka wrote: > I have a CGI application with a datamodule that is using templates to generate the response pages (accessing a MySQL database through ZEOS). > Every once in a while, I'm getting an "Unable to open file" exception that points to one of the templates the website is using. > > What could be the problem? Maybe you run out of file handles? Jonas_______________________________________________

Reply by email

Jonas Maebe
to ABorka
ABorka wrote 16 lines
On 3/14/2010 16:08, Jonas Maebe wrote: > > On 14 Mar 2010, at 23:39, ABorka wrote: > >> I have a CGI application with a datamodule that is using templates >> to generate the response pages (accessing a MySQL database through >> ZEOS). >> Every once in a while, I'm getting an "Unable to open file" >> exception that points to one of the templates the website is using. >> >> What could be the problem? > > Maybe you run out of file handles? > If that is the case, shouldn't something be in the syslog or some other log?

No. It's a generic user error like any other.

Is there any way I can check this for sure like last system error string or something?

You can call sysutils.GetLastOSError and look up the number in errno.inc

The exception message only says that "Unable to open file <filepath_filename>". I checked the /proc/sys/fs/file-max and it shows 294692

The per-user open file handles limit is different. You can see it in the output of "ulimit -a" under bash (if it says "unlimited", it means that it uses the system limit). Maybe you leak file handles somewhere. You can look in /proc/<pid>/fd from time to time to see whether the number of open files keeps growing over time.

Jonas

Reply by email

ABorka
to Jonas Maebe

Thanks for the help.

It appears that the GetLastOSError is 9 for these errors. In the errno.inc for Linux, that is
ESysEBADF = 9; { Bad file number }

I'm not exactly sure what this means though.
Right now as a workaround, when this happens, I do a sleep(100) and retry the page generation and it seems to work.

This only happens when multiple simultaneous requests arrive to the apache server (ex: a dozen iframes hitting cgi calls from a 3rd party website, requesting the same template to be used to generate a response web page with different parameters).

I would like to eliminate this problem in a more elegant way (fix) if it is possible.

AB

Jonas Maebe wrote 31 lines
>>> I have a CGI application with a datamodule that is using templates >>> to generate the response pages (accessing a MySQL database through >>> ZEOS). >>> Every once in a while, I'm getting an "Unable to open file" >>> exception that points to one of the templates the website is using. >>> >>> What could be the problem? >> >> Maybe you run out of file handles? >> > If that is the case, shouldn't something be in the syslog or some > other log? No. It's a generic user error like any other. > Is there any way I can check this for sure like last system error > string or something? You can call sysutils.GetLastOSError and look up the number in errno.inc > The exception message only says that "Unable to open file > <filepath_filename>". > > I checked the /proc/sys/fs/file-max and it shows 294692 The per-user open file handles limit is different. You can see it in the output of "ulimit -a" under bash (if it says "unlimited", it means that it uses the system limit). Maybe you leak file handles somewhere. You can look in /proc/<pid>/fd from time to time to see whether the number of open files keeps growing over time.

Reply by email