red6 / pdfcompare

A simple Java library to compare two PDF files
Apache License 2.0
220 stars 66 forks source link

Is timeout limit adjust through application conf or programatically available? #142

Closed praveenInGit closed 7 months ago

praveenInGit commented 7 months ago

When I use the below code, the compare process is not getting over for the specified time. Means the specified timeout is not creating impact. I also tried using application.conf with overallTimeoutInMinutes=1, but still no impact. Can anyone help? I need to allow the process only for 1 minute. I am using pdfcompare-1.1.61

PdfComparator pdfComparator = new PdfComparator(sourceFilePath, targetFilePath, new CompareResultWithPageOverflow()); Environment customEnvironment = new SimpleEnvironment().setOverallTimeout(1).setActualColor(Color.blue); pdfComparator.withEnvironment(customEnvironment) .compare().writeTo(resultFilePath.getAbsolutePath().replace(".pdf", ""));

finsterwalder commented 7 months ago

You are correct. There are two timeouts. The OverallTimeout is triggered, but then the executors are awaited to stop for up to 15 Minutes after that. This whole process is really just a safety measure agains deadlocks. So when something goes wrong, the process should still terminate after a long waiting period. I could make the second timeout configurable as well. BTW: When timeouts are reached, your Comparison would be incomplete, of course. And I don't know, whether any results are stored. Probably not. You are killing the process in mid flight so to speak.

praveenInGit commented 7 months ago

Thanks for the response @finsterwalder .

finsterwalder commented 7 months ago

I just released version 1.2.0 that allows to configure the executorTimeoutInSeconds in addition to the overallTimeout. See the README.

finsterwalder commented 7 months ago

1.2.0 is available in maven central.

praveenInGit commented 7 months ago

I have used the version 1.2.0. The overallTimeout should be given more than 15 minutes? With the below code the process still goes more than 12 minutes. I thought timeout will occur with 1 minute overallTimeOut + 1 minute executorTimeOut.

Environment customEnvironment = new SimpleEnvironment().setOverallTimeout(1).setExecutorTimeout(60); pdfComparator.withEnvironment(customEnvironment) .compare().writeTo(resultFilePath.getAbsolutePath().replace(".pdf", ""));

finsterwalder commented 7 months ago

Don't know what ".customEnvironment" is. Environment customEnvironment = new SimpleEnvironment().setOverallTimeout(1).setExecutorTimeout(60); My expectation would be, that with the line above, the execution stops after roughly 2 minutes (1min + 60sec).

finsterwalder commented 7 months ago

BTW: The shortest possible setting would be new SimpleEnvironment().setOverallTimeout(1).setExecutorTimeout(1);, which gives you 61 seconds.

praveenInGit commented 7 months ago

Don't know what ".customEnvironment" is. Environment customEnvironment = new SimpleEnvironment().setOverallTimeout(1).setExecutorTimeout(60); My expectation would be, that with the line above, the execution stops after roughly 2 minutes (1min + 60sec).

Sorry ".customEnvironment" was added here mistakenly.

I too thought that the execution will stop after 1min + 60 sec with the above code, but the execution continues to more than 12 minutes. I have attached the sample file which I used to test. row11.pdf

finsterwalder commented 7 months ago

You are right. Pages are queued in an executor service. This executor has a blocking input queue with a maximum of 50. So up to 50 pages are queued. Only after the last 50 pages are queued, the overallTimeout is started. Changing this behaviour will result in a cancellation of large compares earlier. But since the default is 15 minutes, it's probably ok to change that. But when I stop processing in "mid flight" something seams to hang. I will have to look into that some more.