[fpc-devel] "Unable to open file" on Linux randomly in a CGI application when using templates

ABorka fpc-devel at aborka.com
Mon Mar 15 21:02:28 CET 2010


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

On 3/15/2010 02:58, Jonas Maebe 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.




More information about the fpc-devel mailing list