[Xml-compile] Make sure not to block, like on loading external DTDs

Michael Ludwig m.ludwig at epages.com
Tue Feb 21 10:43:06 GMT 2012


I'm doing tests against a service that frequently errors out,
for reasons that are not transparent to me, and they don't
matter much here anyway. And it's not their production service.

What matters is that if an error occurs, it may take several
forms. The service may brutally close the socket, a condition
that is immediately detected, so we know there's an error.

  error: read error

The service may also reply with an HTML document:

  warning: Internal Server Error
  error: answer is not xml but `text/html'

Now I haven't debugged this, but under some circumstances
there's a long wait because something tries to get the HTML
DTD from the W3C website, and they have you wait deliberately
so you learn not to load the DTD from their site, and why
would you?

This blocking wait is of course bad for your application.

Could it be that some parser inside XML::Compile tries to make
sense of the HTML doc and is not configured to avoid loading
the DTD? The option is load_ext_dtd and it defaults to true.

https://metacpan.org/module/XML::LibXML::Parser#PARSER-OPTIONS

Okay, I found it, it's in Trace.pm, it's due to reparsing the
response content when doing pretty print. I'd add some options:

my %opt = (load_ext_dtd => 0, recover => 1);
XML::LibXML->load_xml(location => shift, %opt)->toFH(*STDERR, 1);

This should avoid blocking on loading external DTDs. To be sure,
I'd add:

  no_network => 1

Michael



More information about the Xml-compile mailing list