Mutually exclusive messages logged while session being closed

The following was logged by Smack 4.4.0-alpha2 when the server disconnected Smack.

Smack first logs that it receives a closing element, then it logs “this could happen e.g. if the server closed the connection without sending a closing stream element”. Those two seem mutually exclusive. Does this hint at a larger issue?

Nov 15, 2019 8:27:48 PM org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader parsePackets
INFO: XMPPTCPConnection[leela@laptop-guus/client-1] (0) received closing </stream> element. Server wants to terminate the connection, calling disconnect()

20:27:48.441 client-1: Send: <presence xmlns='jabber:client' id='TSVEF-15' type='unavailable'></presence>

Nov 15, 2019 8:27:48 PM org.jivesoftware.smack.AbstractXMPPConnection waitForClosingStreamTagFromServer
INFO: Exception while waiting for closing stream element from the server XMPPTCPConnection[leela@laptop-guus/client-1] (0)
org.jivesoftware.smack.SmackException$SmackMessageException: Parser got END_DOCUMENT event. This could happen e.g. if the server closed the connection without sending a closing stream element
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1136)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$300(XMPPTCPConnection.java:882)
	at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:902)
	at java.lang.Thread.run(Thread.java:748)
1 Like

I have the same problem in our android application. When the user logins and get this exception, the user should close the program and then relaunch it.

Yep it looks like Smack is waiting for the closing stream element even in the case it was the server we initiated the stream termination by sending it in the first place.

I’ll look into it.

Are you sure that you have the same problem? This is about an exception on stream termination, not initiation.

Yes I am sure. When the user close app and relogin . We got exception server wants to terminate session. then the user should close the app and relaunch again. Sometimes the connection is authenticated when we send for example Iq stanza , It is not sent . after a seconds we get “Exception while waiting for closing stream element from the server” .

I had a closer look and I suspect that the server may closes the TCP connection without waiting for the closing stream tag from the client (while it is supposed to). Could you verify that this is the case?

I also thought openfire closes the session without any reason. I have noticed also that apache mina in openfire is the cause of this disconnection. Now we are modifying openfire to switch from apache mina to netty.

1 Like

Please consider upstreaming your changes, so more users can benefit from your efforts :wink: .

1 Like

I’m facing same problem with smack 4.3.4, please help me how to resolve this.

XMPPTCPConnection: XMPPTCPConnection[xx@xx.xx.xx.xx/android] (0) received closing </stream> element. Server wants to terminate the connection, calling disconnect()
2019-12-17 17:50:45.526 27913-28402/ W/XMPPTCPConnection: Exception flushing queue during shutdown, ignore and continue
    java.net.SocketException: Socket closed
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:124)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
        at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
        at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
        at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
        at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPConnection.java:1587)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$4200(XMPPTCPConnection.java:1368)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1420)
        at java.lang.Thread.run(Thread.java:764)
2019-12-17 17:50:45.529 27913-28402/ W/XMPPTCPConnection: Exception writing closing stream element
    java.net.SocketException: Socket closed
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:124)
        at java.net.SocketOutputStream.write(SocketOutputStream.java:161)
        at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
        at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
        at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
        at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
        at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPConnection.java:1598)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$4200(XMPPTCPConnection.java:1368)
        at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1420)
        at java.lang.Thread.run(Thread.java:764)

I got the same problem:
12-31 14:22:37.777 19813-19910/com.app.test I/XMPPTCPConnection: XMPPTCPConnection[262638100913576@test.love/Android] (0) received closing element. Server wants to terminate the connection, calling disconnect()
12-31 14:22:37.786 19813-19909/com.app.test W/XMPPTCPConnection: Exception flushing queue during shutdown, ignore and continue
java.net.SocketException: Socket is closed
at com.android.org.conscrypt.OpenSSLSocketImpl.checkOpen(OpenSSLSocketImpl.java:246)
at com.android.org.conscrypt.OpenSSLSocketImpl.access$000(OpenSSLSocketImpl.java:57)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:750)
at java.io.OutputStreamWriter.flushBytes(OutputStreamWriter.java:167)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:158)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPConnection.java:1587)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$4200(XMPPTCPConnection.java:1368)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1420)
at java.lang.Thread.run(Thread.java:818)
12-31 14:22:37.787 19813-19909/com.app.test W/XMPPTCPConnection: Exception writing closing stream element
java.net.SocketException: Socket is closed
at com.android.org.conscrypt.OpenSSLSocketImpl.checkOpen(OpenSSLSocketImpl.java:246)
at com.android.org.conscrypt.OpenSSLSocketImpl.access$000(OpenSSLSocketImpl.java:57)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:750)
at java.io.OutputStreamWriter.flushBytes(OutputStreamWriter.java:167)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:158)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPConnection.java:1598)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$4200(XMPPTCPConnection.java:1368)
at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnection.java:1420)
at java.lang.Thread.run(Thread.java:818)

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