-
Notifications
You must be signed in to change notification settings - Fork 16
Ensuring file handles are closed properly
PDF files are stream based. Most of the contents for documents reside in streams. Streams can be:
- Compressed
- Encrypted
- Can be externalized to the PDF files
- Can be used to store PDF objects
This creates the need for accessing them several times in the lifetime of a PDF file access. This means you cannot really parse the PDF files in one go and load all contents into memory. When you try to access a file on-demand multiple number of times you tend to risk possibility of leaving out open handles for files. This can be a problem for non-tolerant OS like Window that locks files before access. However, you may not have a Windows OS with you to test it effectively. Depending on AppVeyor, post every build is a bit of a pain considering you have to check-in before knowing if the file handles are released properly.
Welcome to debugIO
- The file has hooks to add file open requests to a global list and file close requests are deleted from the global list.
All IOStream operations of the files need to be opened with util_open()
and closed with util_close()
. Hence, BufferedInputStream Base.close()
has been overridden to ensure util_close()
is called on the final IOStream.
-
When you are creating temporary files the random nature of the temp files make readability and tractability harder for the temp files. A running counter is introduced to ensure debugging becomes easier in such cases.
-
utilPrintOpenFiles()
is introduced that will print and return the list of open files. -
util_open()
andutil_close()
will print the file that's being opened or closed respectively.
To use ensure that you include the file in the testcase file runtests.jl
Note: Thanks to @tkelman for finding out the temporary files were not getting cleaned up.