Why is my xslt code causing saxonc to bomb?
Asked Answered
N

1

0

I keep getting this error. I'm doing a loop and calling my xslt.transform() method (see listing) about 3 times in a row. It bombs about 50% of the time trying to make it to the end of the loop.

My question is, what is wrong with my code? Am I not calling a method needed to reset the new_xslt30_processor or reset the PySaxonProcessor between each loop? It tends to work the first time through, so that's my hunch. I'm not cleaning up something.

JET RUNTIME HAS DETECTED UNRECOVERABLE ERROR: runtime error Thread C8B63 ["Thread-0"] is terminated without notifying the JVM. Probably, "DetachCurrentThread" function was not called Please, contact the vendor of the application. Core dump will be piped to "/lib/systemd/systemd-coredump %P %u %g %s %t 9223372036854775808 %h" Extra information about error is saved in the "jet_err_822032.txt" file.

xslt.py

import os
import saxonc

from typing import Dict, List

class Xslt():

  @classmethod
  def transform(cls, xsl_file: str, xml_file: str, output_file: str, parameters: Dict[str,str]) -> bool:
    try:
      out = cls.transform_to_string(xsl_file, xml_file, parameters)
      with open(output_file, "w") as f:
        f.write(out)
      return True
    except Exception as e:
      print(str(e))
      return False

  @classmethod
  def transform_to_string(cls, xsl_file: str, xml_file: str, parameters: Dict[str,str]) -> str:
    with saxonc.PySaxonProcessor(license=True) as saxonproc:
      xsltproc = saxonproc.new_xslt30_processor()
      for parameter in parameters:
        xsltproc.set_parameter(parameter, saxonproc.make_string_value(parameters[parameter]))
      saxonproc.set_cwd(os.getcwd())
      return xsltproc.transform_to_string(source_file=xml_file, stylesheet_file=xsl_file)

Output

Error: failed to allocate an object - please check if an exception was thrown proc is nullptr in SaxonProcessor constructor Error: failed to allocate an object - please check if an exception was thrown Error: failed to allocate an object - please check if an exception was thrown Error: failed to allocate an object - please check if an exception was thrown Error: Xslt30Processor not in a clean state. - Exception found

╭─ bash   SaxonHE11-4J  羽393ms⠀                                                   11.0.16     toddmo  104.5.65.251
╰─ff java -cp saxon-he-11.4.jar net.sf.saxon.Version
SAXON-J-HE 11.4 from Saxonica (build 72811)
Neddra answered 16/10, 2022 at 21:0 Comment(4)
When the message says "please contact the vendor of the application" then that's probably the best course of action. Feel free to raise a support request at saxonica.plan.io. You'll need to supply enough information to enable the problem to be reproduced; it might well depend on the exact details of your hardware and sofware configuration.Stonewall
@MichaelKay, ok Sir, I will, after trying a few more things first on my end, to not waste anyone's time. I did see my code doesn't have any obvious missing statements to enable it to work in a loop. It's something about my transform, which is approaching 800 lines now. Perhaps it's so big it's not allowing the processor to recover between loop iterations.Neddra
Until 11.3 there was bug saxonica.plan.io/issues/5533 so depending on which version you use it might be a known issue or at least similar to a known issue.Excursive
@MartinHonnen, it's 11.4 but thanks for the link. ond1's code fixed it for me.Neddra
N
0

OK calling clear_parameters in the last part of transform_to_string appears to fix it:

result = xsltproc.transform_to_string(source_file=xml_file, stylesheet_file=xsl_file)
xsltproc.clear_parameters()
return result

Python is de-allocating the parameters at the end of the function call but saxonc is relying on re-using those if the routine is called multiple times. Clearing the parameters tells saxonc to make them from scratch during each iteration, or each call (my loop is higher up in the call chain).

There still might be a bug, so I'll try to post this in the Saxonica forum as an issue soon.

Neddra answered 17/10, 2022 at 1:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.