[
https://issues.apache.org/jira/browse/PDFBOX-3404?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15366060#comment-15366060
]
Patrick Stahle commented on PDFBOX-3404:
----------------------------------------
As far as we can tell this issue is fixed. We have created a small test java
program to test this. I was able to recreate the problem with an older version
of pdfbox, while the newer version with this fix did not produce the problem.
Also I have only tested this on 2 environments (Oracle Sparc/Solaris & Intel
VBox Linux) and so far I am only able to reproduce it on Sparc/Solaris.
We did run into a few exceptions, however, with both versions. I do not know if
this is another issue or simply is to be expected based on the running
environment. Here are those exception messages:
Jul 07, 2016 8:17:00 AM org.apache.pdfbox.pdmodel.font.PDType1Font <init>
WARNING: Using fallback font ArialMT for base font ZapfDingbats
Exception occured over textwidth! error=U+0048 ('H') is not available in this
font's encoding: WinAnsiEncoding
Exception occured over textwidth! error=U+0048 ('H') is not available in this
font's encoding: WinAnsiEncoding
Here was the test procedure:
Java Source:
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
public class DOCMGMT_2253 extends Thread {
public static void main(String[] args) {
int numThreads = 10; //
number of threads to use in this test.
long considerThreadHungAfterMillis= 1000; // max milliseconds
to wait before considering the thread hung
int errorsDetected = 0;
// Try the init "fix" here once we reproduce the bug
// Create the threads
DOCMGMT_2253 [] threads = new DOCMGMT_2253[numThreads];
for(int i=0; i< numThreads; i++) {
threads[i] = new DOCMGMT_2253("DOCMGMT_2253_"+i);
}
// Start the threads
for(int i=0; i< numThreads; i++) {
threads[i].start();
/*
if (i == 0) {
try {
Thread.sleep(1000);
}
catch(Exception e) {}
}
*/
}
// Wait for the threads to finish
for(int i=0; i< numThreads; i++) {
try {
threads[i].join(considerThreadHungAfterMillis);
System.out.println("Thread " +
threads[i].getName() + " completed.");
}
catch(InterruptedException e) {
//System.err.println("ERR20160706125242: Thread
" + threads[i].getName() + " did not exit after " +
considerThreadHungAfterMillis + " ms");
e.printStackTrace();
errorsDetected++;
}
}
System.out.println("Summary: " + errorsDetected + " error(s)
detected.");
}
public DOCMGMT_2253(String name) {
super(name);
}
public void run() {
//System.out.println("Thread " + getName() + " says 'Put your
code here'");
PDFont font = PDType1Font.HELVETICA;
String line = "Hello World line to calculate.";
try {
float newTextWidth = (font.getStringWidth(line) /
1000.0f) * 34;
}
catch(Exception e) {
System.out.println("Exception occured over textwidth!
error=" + e.getMessage());
}
return;
}
}
RUN WITH OLD JARS (using small perl script to loop over java program):
perl -we 'for($i = 0; $i < 50; $i++) { system("java -cp
./:./jars_old/commons-logging-1.1.1.jar:./jars_old/commons-logging-api-1.1.jar:./jars_old/fontbox-2.0.0-20160314.163507-2077.jar:./jars_old/pdfbox-2.0.0-20160314.163655-2022.jar
DOCMGMT_2253");}'
With the olds jars so far I have not gotten passed 50 before the problem
occurs. At some point it hangs like the following:
WARNING: Using fallback font ArialMT for base font ZapfDingbats
Exception occured over textwidth! error=U+0048 ('H') is not available in this
font's encoding: WinAnsiEncoding
Exception occured over textwidth! error=U+0048 ('H') is not available in this
font's encoding: WinAnsiEncoding
Thread DOCMGMT_2253_2 completed.
Exception occured over textwidth! error=U+0048 ('H') is not available in this
font's encoding: WinAnsiEncoding
Exception occured over textwidth! error=U+0048 ('H') is not available in this
font's encoding: WinAnsiEncoding
Thread DOCMGMT_2253_3 completed.
Exception occured over textwidth! error=U+006F ('o') is not available in this
font's encoding: WinAnsiEncoding
Exception occured over textwidth! error=U+006F ('o') is not available in this
font's encoding: WinAnsiEncoding
Exception occured over textwidth! error=U+006F ('o') is not available in this
font's encoding: WinAnsiEncoding
Exception occured over textwidth! error=U+006F ('o') is not available in this
font's encoding: WinAnsiEncoding
Thread DOCMGMT_2253_4 completed.
Thread DOCMGMT_2253_5 completed.
Thread DOCMGMT_2253_6 completed.
Thread DOCMGMT_2253_7 completed.
Thread DOCMGMT_2253_8 completed.
Thread DOCMGMT_2253_9 completed.
Summary: 0 error(s) detected.
So now to check to state of things I do the following:
ps -ef |grep perl
xxxxxxx 13380 5395 0 08:29:34 pts/58 0:00 perl -we for($i = 0; $i < 50;
$i++) { system("java -cp ./:./jars_old/commons-lo
ptree 13380
31956 zsched
29947 tmux
5252 -bash
5395 -bash
13380 perl -we for($i = 0; $i < 50; $i++) { system("java -cp
./:./jars_old/commons-lo
53792 java -cp
./:./jars_old/commons-logging-1.1.1.jar:./jars_old/commons-logging-api
jstack 53792
2016-07-07 08:39:03
Full thread dump Java HotSpot(TM) Server VM (24.79-b02 mixed mode):
"Attach Listener" daemon prio=3 tid=0x00ee4000 nid=0xb3 waiting on condition
[0x00000000]
java.lang.Thread.State: RUNNABLE
"DestroyJavaVM" prio=3 tid=0x00028400 nid=0x2 waiting on condition [0x00000000]
java.lang.Thread.State: RUNNABLE
"DOCMGMT_2253_1" prio=3 tid=0x008bbc00 nid=0xaa runnable [0xab05f000]
java.lang.Thread.State: RUNNABLE
at java.util.HashMap.put(HashMap.java:494)
at java.util.HashSet.add(HashSet.java:217)
at java.util.AbstractCollection.addAll(AbstractCollection.java:342)
at
org.apache.pdfbox.pdmodel.font.encoding.Encoding.contains(Encoding.java:109)
at
org.apache.pdfbox.pdmodel.font.PDType1Font.encode(PDType1Font.java:343)
at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:286)
at org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth(PDFont.java:315)
at DOCMGMT_2253.run(DOCMGMT_2253.java:67)
"DOCMGMT_2253_0" prio=3 tid=0x008bac00 nid=0xa9 runnable [0xab0ef000]
java.lang.Thread.State: RUNNABLE
at java.util.HashMap.put(HashMap.java:494)
at java.util.HashSet.add(HashSet.java:217)
at java.util.AbstractCollection.addAll(AbstractCollection.java:342)
at
org.apache.pdfbox.pdmodel.font.encoding.Encoding.contains(Encoding.java:109)
at
org.apache.pdfbox.pdmodel.font.PDType1Font.encode(PDType1Font.java:343)
at org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:286)
at org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth(PDFont.java:315)
at DOCMGMT_2253.run(DOCMGMT_2253.java:67)
"Service Thread" daemon prio=3 tid=0x00722000 nid=0xa7 runnable [0x00000000]
java.lang.Thread.State: RUNNABLE
:
:
Note: I have run this 3 times and all 3 times have locked up.
RUN WITH NEW JARS (using small perl script to loop over java program. Bumped up
to loop 150 times.):
perl -we 'for($i = 0; $i < 150; $i++) { system("java -cp
./:./jars_new/commons-logging-1.1.1.jar:./jars_new/commons-logging-api-1.1.jar:./jars_new/fontbox-2.0.3-20160706.181207-87.jar:./jars_new/pdfbox-2.0.3-20160706.181453-84.jar
DOCMGMT_2253");}'
COMPLETES as expected.
Note: I have against new jars 1 time at 50 loops, and 2 times at 150 loops.
> Threads using PDFBox getting stuck when using standard 14 fonts
> ---------------------------------------------------------------
>
> Key: PDFBOX-3404
> URL: https://issues.apache.org/jira/browse/PDFBOX-3404
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 2.0.0, 2.0.2, 2.0.3, 2.1.0
> Reporter: Tilman Hausherr
> Fix For: 2.0.3, 2.1.0
>
>
> user [~prstahle] reports:
> {quote}
> We have a relatively heavily threaded application which is calling pdfbox to
> stamp certain
> pdf files. We have been in production for a little over a week and have run
> into a few threads
> getting stuck. The stack trace is the following:
> {quote}
> {code}
> ### Thread id=34, name="dispatch_2_20160626211454_1064"
> # ThreadInfo: "dispatch_2_20160626211454_1064" Id=34 RUNNABLE
> # CPU: threadCpuTime=49,541,548.824 ms, threadUserTime=49,538,533.066 ms
> # Contention: blockedCount=33 , blockedTime=123 ms
> # Contention: lockName=null , lockOwnerId=-1, lockOwnerName=null
> java.util.HashMap.put(HashMap.java:473)
> java.util.HashSet.add(HashSet.java:217)
> java.util.AbstractCollection.addAll(AbstractCollection.java:334)
> org.apache.pdfbox.pdmodel.font.encoding.Encoding.contains(Encoding.java:109)
> org.apache.pdfbox.pdmodel.font.PDType1Font.encode(PDType1Font.java:343)
> org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:286)
> org.apache.pdfbox.pdmodel.font.PDFont.getStringWidth(PDFont.java:315)
> com.tycoelectronics.emcs.stamppdf.StampEnginePDFBox.getLongestTextWidth(StampEnginePDFBox.java:1369)
> {code}
> {quote}
> We seem to be getting stuck in PDFont classes HashMap which is unsynchronized
> class.
> {quote}
> {quote}
> We are using "PDType1Font.HELVETICA".
> {quote}
> The problem is that for the standard 14 fonts, each font is a singleton, but
> its code is being used multithreaded, so we have to secure that.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]