powered by Jive Software

Frequent XmlPullParserException in Smack 3.2

Hi,

We are facing a very critical issue in our application because of frequent XmlPullParserException coming in our listener side.

Our listener is expecting to get around 1000 packets/min from other users in our system. But once in a while , some packet (of no reason) fails and lead to this Exception and simultaneluy XMPPConnection breaks abruptly of our listener application.

Below are some snippet from logs -

org.xmlpull.v1.XmlPullParserException: entity reference name can not contain character &’

** at org.xmlpull.mxp1.MXParser.parseEntityRef(MXParser.java:2222)**

** at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1275)**

** at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)**

** at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:325)**

** at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)**

** at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)**

**org.xmlpull.v1.XmlPullParserException: end tag name must match start tag name stream:stream from line 1 **

** at org.xmlpull.mxp1.MXParser.parseEndTag(MXParser.java:1689)**

** at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1172)**

** at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)**

** at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:325)**

** at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)**

** at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)**

**org.xmlpull.v1.XmlPullParserException: expected = after attribute name **

** at org.xmlpull.mxp1.MXParser.parseAttribute(MXParser.java:2004)**

** at org.xmlpull.mxp1.MXParser.parseStartTag(MXParser.java:1799)**

** at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1127)**

** at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)**

** at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:325)**

** at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)**

** at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)**

org.xmlpull.v1.XmlPullParserException: end tag name must match start tag name stream:stream from line 1

** at org.xmlpull.mxp1.MXParser.parseEndTag(MXParser.java:1689)**

** at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1131)**

** at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)**

** at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:325)**

** at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)**

** at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)**

We are sending well parsed XML in the message body, so it can’t be that issue.

If all packets fails then its understood , but it fails once in while , that is very strange.

Can some please have a look into these ?

Best Regards,

Keshav

On a first look it seems like a malformed XML character entity reference. Are you 100% sure that the packet is valid XML and that characters like ‘&’ are properly escaped?

I am currenlty working on SMACK-425 which gives you an option to catch those exceptions and examine the unparsed raw XML data later on. This should help you debuging the issue.

Yes we are using a well formed XML , because if not then we will get this exception for every packet rather than for some . Main question is why this happen due to Network load or anything .

What would be the temporary solution for handling these , Please help as it is causing problem to our application.

Regards,

Keshav

keshav badruka wrote:

Yes we are using a well formed XML , because if not then we will

get this exception for every packet rather than for some . Main question is why this happen due to Network load or anything .

This assumption is wrong. It is possible that only certain stanzas contain the malformed entity reference.

You have to find a way to reproduce this exception so that you can examine the stanza that is causing this. I could be wrong but from all I know it is not a parser problem but a syntactically incorrect stanza.

Hi Flow,

I got one very important question like why smack is disconnecting the connection in case of XMLPullParseException, why can’t it just be ignored and continue the packet reading .

We are facing some serious OOME issues because of this Exceptions , can you please provide some help for this.

What about this in PacketReader.java (parsePackets() method)-

try{

eventType = parser.next();

}catch(Exception ex){ } // silently ignore the exception and continue the packet parsing

Or do we need to resetParser() or call PacketReader.init() in case of Exception for a workaround

Please suggest.

Regards,

Keshav

You can’t just ignore errors. Never do that, although java makes it tempting! It does fix nothing and makes things even worse.

If an exception happens when parsing the stream then something unforseen has happened. If you would just ignore the exception then you don’t know the state of the stream, which makes the stream unuseable, because you don’t now where to resume with parsing.

But I am working on SMACK-425 and my patch is nearly finished. It will allow you to define what should happen in case of an exception while parsing. As a special optional feature, it will also be possible to ignore the stanza that caused the exception and place the parser after the faulty stanza. This leaves the stream in a well defined state, because the stanza was just skipped.

It will also provide an callback that contains the raw stanza data that caused the exception. You can then investigate it and determine if the error was caused by an stanza that violates the XMPP/XEP specifications or because Smack isn’t following the specifications.

Beautifull, Thanks Flow.

Can you please let us know when your patch will be available.

Can you attach your patch here when completed or provide with us some repository location.

This patch will be very useful to us.

Regards,

Keshav

Just watch the issue on JIRA with your account. The patch can be found in the svn repo once commited, with is publicly readable.

Hi Flow,

I see like the issue is resolve in JIRA and i have taken the latest code frm GIT as well, but I still see one more place where I think we need to put the try-catch block for handling parsing exception. It is in PacketReader.java , parsePackets() method around (line # 318 in latest code)

eventType = parser.next();

because in our applicaition , we always got XMLPullParseException on this line.

Please confirm.

Thanks,

Keshav

No, that’s nonsense to catch the exception here. Better fix the reason for the exception.