[ 
https://issues.apache.org/jira/browse/PDFBOX-3698?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15876344#comment-15876344
 ] 

Tilman Hausherr commented on PDFBOX-3698:
-----------------------------------------

I don't see why this happens (apparently I'd need to do some deep reading about 
statics initialization) and I can't reproduce it... 

{code}
public class PDFBox3698
{
    public static void main(String[] args) throws IOException, 
InterruptedException
    {
        Thread thread = new Thread(new Runnable()
        {
            @Override
            public void run()
            {
                for (int i = 0; i < 100; i++)
                {
                    try
                    {
                        COSNumber.get("-");
                    }
                    catch (IOException ex)
                    {
                        //
                    }
                }
            }
        });
        thread.start();
        for (int i = 0; i < 100; i++)
        {
            COSInteger.get("-");
        }
        thread.join();
    }
}
{code}
Can you build from source? If yes, can you remove the two deprecated fields in 
COSNumber and tell what happens? If no, would you be willing to test with a 
snapshot?

> Static Initialization Deadlock between COSNumber/COSInteger
> -----------------------------------------------------------
>
>                 Key: PDFBOX-3698
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3698
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.3
>         Environment: Mac OSX 10.12.3, Java(TM) SE Runtime Environment (build 
> 1.8.0_25-b17) Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
>            Reporter: Sean Story
>
> h3. Problem
> Using Tika 1.10 (PDF Box 1.8.10) to parse PDF documents in a multi-threaded 
> application, processing unexpectedly halted. Investigating the output of a 
> {{kill -3}}, we found:
> {noformat}
> "pool-2-thread-18" #50 prio=5 os_prio=0 tid=0x00002af088a67000 nid=0xc9b9 in 
> Object.wait() [0x00002af0dc803000]
>    java.lang.Thread.State: RUNNABLE
>   at 
> org.apache.pdfbox.pdfparser.BaseParser.parseDirObject(BaseParser.java:1348)
> x 15
> "pool-2-thread-13" #45 prio=5 os_prio=0 tid=0x00002af0cf910800 nid=0xc9b4 in 
> Object.wait() [0x00002af0dc2ff000]
>    java.lang.Thread.State: RUNNABLE
>   at org.apache.pdfbox.cos.COSDocument.getObjectFromPool(COSDocument.java:720)
>   at org.apache.pdfbox.pdfparser.PDFParser.parseObject(PDFParser.java:685)
> x 2
> "pool-2-thread-11" #43 prio=5 os_prio=0 tid=0x00002af0cfba6000 nid=0xc9b2 in 
> Object.wait() [0x00002af0dc0fc000]
>    java.lang.Thread.State: RUNNABLE
>   at org.apache.pdfbox.cos.COSNumber.<clinit>(COSNumber.java:33)
>   at 
> org.apache.pdfbox.pdfparser.BaseParser.parseDirObject(BaseParser.java:1348)
> x 1
> {noformat}
> Upon further investigation, it appears that there is a risk for deadlock when 
> BaseParser calls {{COSNumber.get()}} and COSDocument call 
> {{COSInteger.get()}}.
> I was able to semi-reliably replicate this issue with the below Spock test:
> {noformat}
> import org.apache.pdfbox.cos.COSInteger
> import org.apache.pdfbox.cos.COSNumber
> import spock.lang.Specification
> class ThreadingIssueSpec extends Specification{
>     def "testy test"(){
>         setup:
>         Thread thread = new Thread(new Runnable(){
>             @Override
>             void run() {
>                 for (int i =0; i<100; i++){
>                     COSNumber.get("-")
>                 }
>             }
>         })
>         thread.start()
>         for(int i =0; i<100; i++) {
>             COSInteger.get("-")
>         }
>         thread.join()
>         expect:
>         1==1
>     }
> }
> {noformat}
> (you'll likely need to run this several times before the test hangs, but it 
> does eventually hang)
> I updated my Tika dep to 1.14 (PDF Box 2.0.3) and was still able to replicate 
> this issue.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to