100 lines
4.3 KiB

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE xep SYSTEM 'xep.dtd' [
<!ENTITY % ents SYSTEM 'xep.ent'>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<title>Best Practice for Closing Idle Streams</title>
<abstract>This document specifies a best practice for closing an XML stream that is perceived to be idle.</abstract>
<spec>XMPP Core</spec>
<spec>RFC 6120</spec>
<surname>von Loesch</surname>
<remark><p>Changed status to Obsolete because it is superseded by RFC 6120.</p></remark>
<remark>Per a vote of the XMPP Council, advanced status to Active.</remark>
<remark><p>Initial version.</p></remark>
<remark>Second draft.</remark>
<remark>First draft.</remark>
<section1 topic='Introduction' anchor='intro'>
<p><cite>RFC 3920</cite> describes several ways to terminate an XML stream, but does not always make a clear statement about which to use. This can lead to faulty implementations. In particular, closing a stream that has not been in use for a while is very often achieved using a connection-timeout error, then closing the socket. This can lead to loss of data. Therefore this document proposes a practice that will avoid such data loss.</p>
<p>Note: The recommendation described herein has been incorporated into &rfc6120;.</p>
<section1 topic='How to Close an Idle Stream' anchor='do'>
<section2 topic='Handshake Stream Shutdown'>
<p>As shown in the basic "session" example in the Simplified Stream Examples (4.8 of RFC 3920), it is a valid transaction to close the outgoing stream by sending</p>
<p>then wait for the other entity to close its stream, like this:</p>
<p>and shut down the underlying TCP connection.</p>
<p>This will ensure that, should the other entity have transmitted any data, it will arrive and be processed before the TCP connection is terminated.</p>
<p>Special care MUST be taken that under no circumstance further packets may be written to the socket after the stream was closed, until the other side shuts down the socket.</p>
<p>On the outgoing TCP connection, an implementation MAY do a read-only shutdown of the socket, as long as the other side will safely be able to send its stream termination token.</p>
<section2 topic='Handshake Failure'>
<p>In case the other entity fails to close the stream within a reasonable time frame, the entity that started the handshake is entitled to terminate the TCP connection. Since the stream has already been closed, it is correct not to produce an error condition.</p>
<section1 topic='Implementation Notes' anchor='impl'>
<p>Existing implementations should be updated to use the 'Handshake Stream Shutdown' strategy when shutting down streams that are no longer needed. This strategy is fully backwards-compatible and does not introduce any known communication problems.</p>
<section1 topic='Security Considerations' anchor='security'>
<p>This proposal introduces no new security aspects.</p>
<section1 topic='IANA Considerations' anchor='iana'>
<p>This proposal requires no interaction with &IANA;.</p>
<section1 topic='XMPP Registrar Considerations' anchor='registrar'>
<p>This proposal requires no interaction with the &REGISTRAR;.</p>