# why lualatex gives erorr “Too many open files” but pdflatex does not on same latex file?

Using TL 2015 on Linux.

I have a latex file which includes graphics, all in pdf format. All the images are included using the call

\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{rules/file_name}


There is a total of 1860 such images, all in pdf format.

When I compile this file using lualatex, at some stage, when it gets to image number 1016, it fails with the error Too many open files. Compiling the same file with pdflatex gives no error !

Is there a limitation on how images one can include in a latex file when using lualatex or is this a bug? It looks like lualatex includegraphics version is not closing file handles when loading images and running out of file handles. This is on Linux mint 7.2.

Since the file is large. I have put the file and the images it loads using \includegraphics in one zip file (80 MB). The link is at the bottom of this post.

To reproduce, please download the zip file, unzip it using the command unzip file.zip and it will create a new folder called lualatex_error/ and inside this folder there is the one file report.tex and the folder that includes all the images. Then typing

lualatex report.tex


will give the error

 lualatex: ./rules/1016.pdf: Too many open files


From the report.log

This is LuaTeX, Version beta-0.80.0 (TeX Live 2015) (rev 5238)
(format=lualatex 2015.7.9)  31 JUL 2015 12:28
restricted \write18 enabled.

lualatex_error>which lualatex
/usr/local/texlive/2015/bin/x86_64-linux/lualatex


The zip file is in this folder (This is a link to the folder where the zip file is in. Not a direct link to the zip file). 80 MB size.

Any other information I can give please let me know.

• A problem: "You don't have permission to access the requested resource. Please contact the web site owner for further assistance." – user2478 Jul 31 '15 at 17:56
• 190,000 lines of lualatex code are too dangerous! – Paul Gaborit Jul 31 '15 at 23:36
• @PaulGaborit See my (non)-answer for a way to reproduce the error without that. – cfr Aug 1 '15 at 2:07
• @Herbert You don't need the OP's code to reproduce the error. – cfr Aug 1 '15 at 2:07
• @Nasser You need to set a new limit e.g. ulimit -n 2000. This assumes you are using bash. If you use a different shell, the syntax might vary as ulimit -n is not in the POSIX spec. – cfr Aug 1 '15 at 20:59

I can confirm this behaviour. To test:

Create 1860 copies of example-image-1x1.pdf (or other image of your choosing) named 1.pdf, 2.pdf,..., 1860.pdf. If you use bash and you have TeX Live 2015 installed in the standard place, you can use the following commands:

i=0; while [ $i -le 1860 ] ; do ((i++)); cp /usr/local/texlive/current/texmf-dist/tex/latex/mwe/example-image-1x1.pdf ./$i.pdf; done


Then create the following document:

\documentclass{article}
\usepackage{graphicx}
\usepackage{expl3,xparse}
\ExplSyntaxOn
\int_new:N \l_nasser_loop_int
\tl_new:N \l_nasser_file_tl
\NewDocumentCommand \icing { }
{
\int_set:Nn \l_nasser_loop_int { 0 }
\int_do_while:nNnn { \l_nasser_loop_int } < { 1860 }
{
\int_incr:N \l_nasser_loop_int
\tl_set:Nn \l_nasser_file_tl { \int_use:N \l_nasser_loop_int }
\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{\l_nasser_file_tl}\par
}
}
\ExplSyntaxOff
\begin{document}
\icing
\end{document}


This compiles fine with pdflatex. With lualatex, it fails with the following error:

lualatex: ./1024.pdf: Too many open files


I will refrain from posting the output pdflatex produces: you will either have to take my word for it or follow the procedure above.

• LuaTeX, beta-0.80, rev 5238: Port x86_64-cygwin of TL 2015 breaks at image 3196.pdf, whereas the MiKTeX port (32 bit) runs fine with 10000 images. – Heiko Oberdiek Aug 1 '15 at 5:45
• At each page during output, luatex opens all external PDF pictures of the page but close only the last opened picture... – Paul Gaborit Aug 1 '15 at 8:06
• To test with a small number of pictures, you can use the following command: limit descriptors 20 – Paul Gaborit Aug 1 '15 at 8:07
• On windows it works without problems. I tested with 5000 pictures on miktex (32bit, LuaTeX, Version beta-0.80.0 (MiKTeX 2.9) (rev 5238)) and texlive 2015 (LuaTeX, Version beta-0.80.0 (TeX Live 2015/W32TeX) (rev 5238)). – Ulrike Fischer Aug 1 '15 at 9:37
• @cfr With bash, try ulimit -n 20 – Paul Gaborit Aug 1 '15 at 13:53