Saturday, October 1, 2022
HomeJavaTroubleshooting impasse in an Apache opensource library - Java Code Geeks

Troubleshooting impasse in an Apache opensource library – Java Code Geeks


Apache PDFBox is a well-liked open-source library that facilitates java functions to work with PDF paperwork. Not too long ago we encountered a Impasse that surfaced on this library. On this publish we have now shared how we troubleshooted and recognized the foundation explanation for the issue.

What’s Impasse?

First let’s attempt to perceive what ‘Impasse’ means. A number of technical definitions aren’t clear. ‘Impasse’ definition is one amongst them :-). Impasse’s definition goes like this: “Impasse is a state of affairs the place a set of processes are blocked as a result of every course of is holding a useful resource and ready for one more useful resource acquired by another course of.” It’s at all times simpler to be taught one thing new by way of examples and footage. Let’s take a look at the under sensible instance, which can provide help to to grasp Impasse higher.

Let’s say there is just one practice observe, and this practice observe has six elements(part-1, part-2, part-3, part-4, part-5, part-6). Prepare-A begins at part-1 and Prepare-B begins at Half-6 on the identical practice observe on the similar time. Each trains journey on the similar velocity. Underneath this circumstance, Prepare-A and Prepare-B will attain a Impasse state after they attain part-3 and part-4 of the practice observe. As a result of when Prepare-A is in part-3 of the practice observe, it will likely be caught ready for part-4 of the observe, which Prepare-B holds. Then again, when Prepare-B is in part-4, it will likely be caught ready for part-3, which Prepare-A holds. Thus, each the trains can’t transfer ahead. It is a basic Impasse state of affairs. Equally, as soon as a Impasse occurs within the utility, it can’t be recovered. The one method to get well from Impasse is to restart the appliance. To be taught extra about Impasse fundamentals & troubleshooting, chances are you’ll discuss with this weblog publish.

Troubleshooting Impasse

Now let’s talk about concerning the Impasse drawback we confronted within the utility. From the above clarification you possibly can perceive that Impasse is triggered on account of threads. Thus, to investigate Impasse, you should seize thread dump from the appliance. Thread dump is mainly a snapshot of all threads which might be working in your utility. It comprises info similar to: stack hint, thread state, thread precedence, … You may seize thread dump utilizing one of many approaches given right here.

Word: More often than not, you'll not know whether or not the precise drawback in your utility is impasse or not. What you'll discover is unresponsiveness from the appliance. Thus, it’s secure to seize all of the outstanding artifacts which might be important for troubleshooting similar to: Rubbish Assortment log, thread dump, heap dump, netstat, iostat,… chances are you'll use yCrash open supply script, which might seize 360-degree information (GC log, 3 snapshots of thread dump, heap dump, netstat, iostat, vmstat, high, high -H,…) out of your utility stack inside a minute and generate a bundle zip file.

We uploaded the captured thread dump to fastThread – a thread dump evaluation software. Instrument instantly identified that the 2 threads triggered the impasse. Under is the excerpt from the fastThread report.

Instrument identified the stack hint of the 2 threads that have been in impasse. Under is the stack hint of these two threads:

"APP_Thread_50_WorkerTask_pool-5-thread-6" #1899 prio=5 os_prio=0 tid=0x00007f894c405555 nid=0x44d1 ready for monitor entry [0x00007f88e9c44000]
   java.lang.Thread.State: BLOCKED (on object monitor)
	at org.apache.fontbox.ttf.TrueTypeFont.getTable(TrueTypeFont.java:147)
	- ready to lock <0x00000002d216fec8> (a org.apache.fontbox.ttf.TrueTypeFont)
	at org.apache.fontbox.ttf.TrueTypeFont.getHorizontalMetrics(TrueTypeFont.java:229)
	at org.apache.fontbox.ttf.GlyphTable.getGlyphData(GlyphTable.java:210)
	at org.apache.fontbox.ttf.GlyphTable.getGlyph(GlyphTable.java:191)
	- locked <0x00000002d218ca28> (a org.apache.fontbox.ttf.RAFDataStream)
	at org.apache.fontbox.ttf.TrueTypeFont.getPath(TrueTypeFont.java:676)
	at org.apache.pdfbox.pdmodel.font.PDType1Font.getPath(PDType1Font.java:638)
	at org.apache.pdfbox.rendering.Type1Glyph2D.getPathForCharacterCode(Type1Glyph2D.java:83)
	at org.apache.pdfbox.rendering.PageDrawer.drawGlyph2D(PageDrawer.java:495)
	at org.apache.pdfbox.rendering.PageDrawer.showFontGlyph(PageDrawer.java:476)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.showGlyph(PDFStreamEngine.java:787)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.showGlyph(PDFStreamEngine.java:805)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.showText(PDFStreamEngine.java:743)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.showTextString(PDFStreamEngine.java:606)
	at org.apache.pdfbox.Contentstream.operator.textual content.ShowText.course of(ShowText.java:56)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:933)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:514)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:492)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:155)
	at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:277)
	at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:347)
	at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:268)
	at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:228)
	at xxxxxxx.export.service.thumbnail.PDFSlideGeneratorServiceImpl$1.name(PDFSlideGeneratorServiceImpl.java:60)
	at xxxxxxx.ops.executor.util.ParallelExecutorTask.doCall(ParallelExecutorTask.java:43)
	at xxxxxxx.ops.executor.util.ParallelExecutor.executeTaskFromQueue(ParallelExecutor.java:154)
	at xxxxxxx.ops.executor.util.ParallelExecutor.entry$100(ParallelExecutor.java:26)
	at xxxxxxx.ops.executor.util.ParallelExecutor$WorkerTask.doCall(ParallelExecutor.java:164)
	at xxxxxxx.ops.executor.util.UserContextAwareCallable.name(UserContextAwareCallable.java:89)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Employee.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
"APP_Thread_WorkerTask_APP-pool-5-thread-5" #1898 prio=5 os_prio=0 tid=0x00007f894c898900 nid=0x44d0 ready for monitor entry [0x00007f88e9d45000]
   java.lang.Thread.State: BLOCKED (on object monitor)
	at org.apache.fontbox.ttf.TrueTypeFont.readTable(TrueTypeFont.java:356)
	- ready to lock <0x00000002d218ca28> (a org.apache.fontbox.ttf.RAFDataStream)
	at org.apache.fontbox.ttf.TrueTypeFont.getTable(TrueTypeFont.java:150)
	- locked <0x00000002d216fec8> (a org.apache.fontbox.ttf.TrueTypeFont)
	at org.apache.fontbox.ttf.TrueTypeFont.getCmap(TrueTypeFont.java:262)
	at org.apache.fontbox.ttf.TrueTypeFont.getUnicodeCmapImpl(TrueTypeFont.java:556)
	at org.apache.fontbox.ttf.TrueTypeFont.getUnicodeCmapLookup(TrueTypeFont.java:541)
	at org.apache.fontbox.ttf.TrueTypeFont.nameToGID(TrueTypeFont.java:629)
	at org.apache.fontbox.ttf.TrueTypeFont.hasGlyph(TrueTypeFont.java:698)
	at org.apache.pdfbox.pdmodel.font.PDType1Font.getNameInFont(PDType1Font.java:601)
	at org.apache.pdfbox.pdmodel.font.PDType1Font.hasGlyph(PDType1Font.java:645)
	at org.apache.pdfbox.rendering.Type1Glyph2D.getPathForCharacterCode(Type1Glyph2D.java:59)
	at org.apache.pdfbox.rendering.PageDrawer.drawGlyph2D(PageDrawer.java:495)
	at org.apache.pdfbox.rendering.PageDrawer.showFontGlyph(PageDrawer.java:476)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.showGlyph(PDFStreamEngine.java:787)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.showGlyph(PDFStreamEngine.java:805)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.showText(PDFStreamEngine.java:743)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.showTextString(PDFStreamEngine.java:606)
	at org.apache.pdfbox.Contentstream.operator.textual content.ShowText.course of(ShowText.java:56)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:933)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:514)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:492)
	at org.apache.pdfbox.Contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:155)
	at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:277)
	at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:347)
	at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:268)
	at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:228)
	at xxxxxxx.export.service.thumbnail.PDFSlideGeneratorServiceImpl$1.name(PDFSlideGeneratorServiceImpl.java:60)
	at xxxxxxx.ops.executor.util.ParallelExecutorTask.doCall(ParallelExecutorTask.java:43)
	at xxxxxxx.ops.executor.util.ParallelExecutor.executeTaskFromQueue(ParallelExecutor.java:154)
	at xxxxxxx.ops.executor.util.ParallelExecutor.entry$100(ParallelExecutor.java:26)
	at xxxxxxx.ops.executor.util.ParallelExecutor$WorkerTask.doCall(ParallelExecutor.java:164)
	at xxxxxxx.ops.executor.util.UserContextAwareCallable.name(UserContextAwareCallable.java:89)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Employee.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

You may see the ‘APP_Thread_50_WorkerTask_pool-5-thread-6’ thread is in Impasse with ‘APP_Thread_50_WorkerTask_pool-5-thread-5’ thread. From the stacktrace you possibly can observe following two issues:

  1. ‘APP_Thread_50_WorkerTask_pool-5-thread-6’ has acquired the lock ‘0x00000002d218ca28’ of the ‘org.apache.fontbox.ttf.RAFDataStream’ object and ready to accumulate the lock ‘0x00000002d216fec8’ of the ‘org.apache.fontbox.ttf.TrueTypeFont’ object. 
  2. Then again, ‘APP_Thread_50_WorkerTask_pool-5-thread-5’ thread is making an attempt to do the precise reverse, it acquired the lock ‘0x00000002d216fec8’ of ‘org.apache.fontbox.ttf.TrueTypeFont’ object and ready to accumulate the lock ‘0x00000002d218ca28’ of the ‘org.apache.fontbox.ttf.RAFDataStream’ object. 

Certainly, it’s a basic Impasse situation. 

Impasse in Apache PDFBox

In the event you discover two objects that are inflicting Impasse are ‘org.apache.fontbox.ttf.TrueTypeFont’ and ‘org.apache.fontbox.ttf.RAFDataStream’. Each of those objects are originating from the open supply Apache PDFBox library.

As soon as seeing this bug, we searched within the Apache PDFBox bug database to see whether or not this drawback was already reported or not. We couldn’t see this drawback reported earlier. Thus, we went forward and filed a brand new ticket within the Apache bug database with the main points. Right here is the ticket that we filed, on your reference. The Apache PDFBox improvement staff was extremely responsive. They began appearing on it immediately and issued a repair inside 2 – 3 days. Nice job from the PDFBox staff. Actually loved the open supply neighborhood collaboration.

Video

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments