powered by Jive Software

XmlPullParserException when calling XMPPTCPConnection.disconnect()

I am using Smack V4.4.1. When I close a previously opened XMPP connection by calling XMPPTCPConnection.disconnect(), I get the following exception:

Mar 08, 2021 4:44:52 PM org.jivesoftware.smack.AbstractXMPPConnection waitForClosingStreamTagFromServer
INFO: Exception while waiting for closing stream element from the server XMPPTCPConnection[85744@eu92b-fin002.labalz.aeat.allianz.at/AgentID@85744] (0)
org.jivesoftware.smack.SmackException$SmackWrappedException: org.jivesoftware.smack.xml.XmlPullParserException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[82,231]
Message: XML document structures must start and end within the same entity.
at org.jivesoftware.smack.AbstractXMPPConnection.setCurrentConnectionExceptionAndNotify(AbstractXMPPConnection.java:690)
at org.jivesoftware.smack.AbstractXMPPConnection.notifyConnectionError(AbstractXMPPConnection.java:994)
at org.jivesoftware.smack.tcp.XMPPTCPConnection.access$4100(XMPPTCPConnection.java:130)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1152)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$700(XMPPTCPConnection.java:913)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:936)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.jivesoftware.smack.xml.XmlPullParserException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[82,231]
Message: XML document structures must start and end within the same entity.
at org.jivesoftware.smack.xml.stax.StaxXmlPullParser.next(StaxXmlPullParser.java:194)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1140)
… 3 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[82,231]
Message: XML document structures must start and end within the same entity.
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652)
at org.jivesoftware.smack.xml.stax.StaxXmlPullParser.next(StaxXmlPullParser.java:192)
… 4 more

The exception comes from XMPPTCPConnection.shutdown(false) after calling waitForClosingStreamTagFromServer().

My code for opening the XMPP connection is the following:

ReconnectionManager.setEnabledPerDefault(false); Builder builder = XMPPTCPConnectionConfiguration.builder().setHost().setPort().addEnabledSaslMechanism(SASLPlainMechanism.NAME).setSecurityMode(SecurityMode.disabled); builder.setXmppDomain();

XMPPTCPConnectionConfiguration config = builder.build();

XMPPTCPConnection xmppConnection = new XMPPTCPConnection(config);
xmppConnection.connect();

The code for disconnect is simply:

xmppConnection.disconnect();

Any hints?

Thanks!

Zoltan

Could be that the server is not terminating the stream with a closing stream tag. Hard to tell without further data. Enable SmackConfiguration.DEBUG and retrieve an XMPP trace of the connection.

I don’t see any additional packets after the call of XMPPTCPConnection.waitForClosingStreamTagFromServer() in Smack Debug Window/Raw Recieved Packets. The last packet, that was received before the call was:

<a xmlns=‘urn:xmpp:sm:3’ h=‘10’ />
<presence id=“TWYWL-2” type=“unavailable” from=“85744@host/AgentID@85744” to=“85744@host/AgentID@85744”/>

But you see that Smack sends a closing stream tag, i.e. </stream:stream>?

Yes. These are the last packets sent by Smack before calling XMPPTCPConnection.waitForClosingStreamTagFromServer()

<presence id=‘HHDHF-2’ type=‘unavailable’/>
<a xmlns=‘urn:xmpp:sm:3’ h=‘15’/>
</stream:stream>

The server should response to a closing stream tag from the client with a clean stream shutdown. Could be possible that this is not the case, check the server log if one is send, and if not, report this to your server vendor.

Just to clarify: This does not cause any issues for you, or does it? As far as I can tell, you merely see a logged exception, recorded with ‘info’ log level.

The server is a Cisco Finesse server. For failsafe operation, we have two Finesse servers running. When the ConnectionListener.connectionClosedOnError() is triggered, we switch to the other server. But during the switch (where we call XMPPConnection.disconnect()) this issue calls the listener again and we end up switching the servers until we give up. So it seems I have to build a workaround for that.

One second. This

should not result in the connectionClosedOnError() callback being invoked. If this happens, then it’s potentially a Smack bug.

Which exception do you see in the connectionClosedOnError() callback?

This is the exception:

org.jivesoftware.smack.xml.XmlPullParserException: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[82,4153]
Message: XML document structures must start and end within the same entity.
at org.jivesoftware.smack.xml.stax.StaxXmlPullParser.next(StaxXmlPullParser.java:194)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1140)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$700(XMPPTCPConnection.java:913)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:936)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[82,4153]
Message: XML document structures must start and end within the same entity.
at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652)
at org.jivesoftware.smack.xml.stax.StaxXmlPullParser.next(StaxXmlPullParser.java:192)
… 4 more

Should be fixed with

Which will probably land in Smack 4.4.2.

Thanks a lot! :slight_smile:

You are welcome.

Are you able to test this fix and report back? I’ve just made this available as Smack 4.4.2-SNAPSHOT on Maven Central’s snapshot repositories: https://oss.sonatype.org/content/repositories/snapshots/org/igniterealtime/smack/

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.