Static Publishing Seems to be Keeping Files Open
For project-8, attempting to static push an entire site to S3 bucket. After about an hour, the push publishing fails. The timing of this failure coincides with "Too many open files" being logged in the dotcms.log file.
Once the server is in this state, ran lsof to get a list of open files. The java process had over 65K files open. Over 32K of those filenames end with ".fileAsset.xml".
-bash-4.2$ ulimit
unlimited
-bash-4.2$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 64126
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65536
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 64126
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
Steps to Reproduce (for bugs)
Presumably, this would be reproducible when static pushing using a dataset with over 65K file assets.
Your Environment
- dotCMS version used: latest project-8 build
- Browser Name and version: N/A
- Operating System and version: "Amazon Linux AMI release 2017.03"
- Application Server and version: Standalone Apache Tomcat 8.5.15
- Java Brand and version: OpenJDK Runtime Environment (build 1.8.0_141-b16)
- Database and version: Postgres RDS
- Application module (if apply): N/A
Relevant log and support files are located here: https://drive.google.com/open?id=0BwenB5wlEw5mODZvS1Z0eWYtd2M
it would appear that these files are not left open indefinitely. After all retry attempts are done, I ran another list of open files and only 449 files are left open.
Aside from the direct ulimit failure, this behavior is probably also causing significant memory and GC issues on both the JVM and the host OS. Ref: https://dzone.com/articles/fileinputstream-fileoutputstream-considered-harmful
how is this code not reading the whole file into memory?
https://github.com/dotCMS/enterprise-2.x/compare/issue-12265-open-file-handles?expand=1#diff-00351b548497f2c52060bb0b661271d8L229
So, Chris came up with the idea to log the count of file handles. If necessary we can provide the entire log file tomorrow, but the high level findings are clear. The file handles stayed very low until this was logged in dotcms.log:
[07/08/17 21:24:30:490 PDT] INFO publishing.PublisherAPIImpl: End of Bundler: e
[07/08/17 21:24:30:492 PDT] INFO pusher.PushUtils: Compressing 1 to /opt/dotcms/shared/assets/bundles/bd7488f2-a4f1-4d8a-8f88-28df1d8e0a41-static/../bd7488f2-a4f1-4d8a-8f88-28df1d8e0a41.tar.gz
It would appear that the file handle problem only occurs after the bundler is finished and most likely during the actual creation of the tar.gz file. Promptly at 21:24:30, the file handles started climbing steadily upward until it hit our new limit of 131K.
i think this is the issue https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotcms/publisher/pusher/PushUtils.java#L79
Need to close that stream.
see example here - see second answer: https://stackoverflow.com/questions/13461393/compress-directory-to-tar-gz-with-commons-compress
https://github.com/dotCMS/core/pull/12277/files
PR master: https://github.com/dotCMS/core/pull/12302 PR p8: https://github.com/dotCMS/core/pull/12300
Passed QA. Fix tested with latest master using client dataset and is working as expected per Brent