Free Support Forum - aspose.cloud

PDF conversion to html crashes our server with sigsegv fault

We have a service running on aws cloud. After we introduced aspose pdf for java, the server starts to crash a few times a day. Note that it is evaluation version, so no one really used it. We noticed that, even if no uses the pdf to html conversion function, as long as aspose classes are loaded, crashes will happen. Below is the code which does the conversion (again, the code was not even invoked):


public byte[] convertPDFToFile(byte[] data, int convertToFormat)

{

InputStream in = new ByteArrayInputStream(data);

com.aspose.pdf.Document doc = new com.aspose.pdf.Document(in);

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

if (convertToFormat == com.aspose.pdf.SaveFormat.Html)

{

String file = folder + File.separator + data.length + "_" + getCount() + ".html";

com.aspose.pdf.HtmlSaveOptions options = new com.aspose.pdf.HtmlSaveOptions();

options.setDocumentType(com.aspose.pdf.SaveFormat.Html);

options.RasterImagesSavingMode = com.aspose.pdf.HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;

//options.FontSavingMode = com.aspose.pdf.HtmlSaveOptions.FontSavingModes.SaveInAllFormats;

options.PartsEmbeddingMode = com.aspose.pdf.HtmlSaveOptions.PartsEmbeddingModes.EmbedAllIntoHtml;

options.LettersPositioningMethod = com.aspose.pdf.LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;

//options.setSplitIntoPages(true);// force write HTMLs of all pages into one output document

doc.save(file, options);

try

{

InputStream inp = new FileInputStream(file);

byte[] bytes = IOUtils.toByteArray(inp);

try

{

inp.close();

File f = new File(file);

f.delete();

}

catch (Exception e)

{

log.error("Error deleting file: " + file, e);

}

return bytes;

}

catch (Exception e)

{

log.error("Error reading file: " + file, e);

return "Document failed to convert to html".getBytes();

}

}

else

{

doc.save(outputStream, convertToFormat);

}

return outputStream.toByteArray();

}


Also, we did not notice any exceptions. So not much more information could be provided.


Please help, since this is affecting our production.

Hi Chris,


Thanks for contacting support.

I have tested the scenario in simple Eclipse Juno application with JDK 1.7 and I am unable to notice any issue. However as per my observations, you might be getting error because you are trying to delete resultant file right after conversion and there might be case that HTML file is being generated and before the process is complete (or all resources are added), the application tries to access and delete the resultant file.

May be you can comment out file deletion code and try the conversion. In case the problem still persists, please share the Stack trace and some details regarding your working environment.

We are sorry for this inconvenience.

Hi Nayyer,

Thanks for your response!

I am listing the symptoms below so that it is easier to understand:

1. The problem will not happen right away - the server will run for sometime (any where between 3 minutes and 3 hours depending on virtual machine configuration) before it crashed. So it is not easy to reproduce.
2. Even if we don’t trigger this function - just let the server be idle there, after some time the server will crash. I can definitely comment the file deletion lines but it might not be related. I will let you know once I have done with that.

Thanks,

Chris

Also, I forgot to mention that there is no exceptions so there is no stack trace available. So this is another hint that the file deletion may not be an issue.

Hi Nayyer,

After some more testing, I believe the problem is related to JDK. When we build the project with open JDK, we got this problem. When build it using Oracle JDK, we don’t have this problem. I think aspose combined with open JDK produces this problem.

Could you please look into it?

Thanks,

Chris

Hi Chris,


Thanks for sharing the details.

I have tried downloading OpenJDK but could not find any appropriate link. Can you please share the OpenJDK so that we can test the conversion in our environment.

You may consider uploading JDK to free file sharer and share the link with us.

Hi Nayyer,

Sorry for the late response. I was creating a separate project for this problem and it took some time. Here is the open jdk info:

java version "1.6.0_30"
OpenJDK Runtime Environment (IcedTea6 1.13.3) (amazon-67.1.13.3.64.amzn1-x86_64)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)

If you could not find this jdk please let me know. I will get you a copy.

Thanks,

Chris

Additional info:

After I removed the file deletion piece, we still got this problem.

Additional info:

This is built and run on:

<span style=“font-size:
10.5pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:“Times New Roman”;
position:relative;top:-1.5pt;mso-text-raise:1.5pt;background:#DDFADE;
mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>Amazon Linux AMI release 2013.03
<span style=“font-size:10.5pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:
“Times New Roman”;position:relative;top:-1.5pt;mso-text-raise:1.5pt;mso-ansi-language:
EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:AR-SA”>

Thanks,

Chris
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>ZH-CN</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman","serif";}

<![endif]–>

Additional info:

According to icedtea, the problem is:

This crash appears to be https://bugs.openjdk.java.net/browse/JDK-8020190, which is caused by the native code using the scaler in places where it should use the font object. It is fixed in JDK 8.

This is the icedtea bug link:

http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=1326

Hi Chris,


Thanks for sharing the details.

As per my understanding, the problem is resolved when using latest release of JDK 1.8. Please acknowledge and in case the issue still persists, please do let me know.