XEP-0190: Best Practice for Closing Idle Streams

This document specifies best practice for closing an idle XMPP stream.


NOTICE: This document is currently within Last Call or under consideration by the XMPP Council for advancement to the next stage in the JSF standards process.


Document Information

Status: Proposed
Type: Informational
Number: 0190
Version: 0.1
Last Updated: 2006-07-26
Publishing Organization: Jabber Software Foundation
Approving Body: XMPP Council
Dependencies: XMPP Core
Supersedes: None
Superseded By: None
Short Name: N/A
Wiki Page: <http://wiki.jabber.org/index.php/Best Practice for Closing Idle Streams (XEP-0190)>

Author Information

Carlo von Loesch

Email: lynX@jabber.getting.psyced.org
JID: lynX@ve.symlynX.com

Legal Notice

This XMPP Extension Protocol is copyright 1999 - 2006 by the Jabber Software Foundation (JSF) and is in full conformance with the JSF's Intellectual Property Rights Policy <http://www.xmpp.org/extensions/ipr-policy.shtml>. This material may be distributed only subject to the terms and conditions set forth in the Creative Commons Attribution License (<http://creativecommons.org/licenses/by/2.5/>).

Discussion Venue

The preferred venue for discussion of this document is the Standards-JIG discussion list: <http://mail.jabber.org/mailman/listinfo/standards-jig>.

Relation to XMPP

The Extensible Messaging and Presence Protocol (XMPP) is defined in the XMPP Core (RFC 3920) and XMPP IM (RFC 3921) specifications contributed by the Jabber Software Foundation to the Internet Standards Process, which is managed by the Internet Engineering Task Force in accordance with RFC 2026. Any protocol defined in this document has been developed outside the Internet Standards Process and is to be understood as an extension to XMPP rather than as an evolution, development, or modification of XMPP itself.

Conformance Terms

The following keywords as used in this document are to be interpreted as described in RFC 2119: "MUST", "SHALL", "REQUIRED"; "MUST NOT", "SHALL NOT"; "SHOULD", "RECOMMENDED"; "SHOULD NOT", "NOT RECOMMENDED"; "MAY", "OPTIONAL".


Table of Contents

1. Introduction
2. How to Close an Idle Stream
2.1. Handshake Stream Shutdown
2.2. Handshake Failure
3. Conclusion
4. Security Considerations
5. IANA Considerations
6. XMPP Registrar Considerations
Notes
Revision History


1. Introduction

Note: This document describes a protocol or best practice that is intended for incorporation into the specification that will supersede RFC 3920 [1] within the Internet Standards Process, i.e., rfc3920bis [2]. This document is provided only for the purpose of open community discussion of the potential modification and will be obsoleted as soon as the relevant RFC is published.

RFC 3920 offers several ways on how to terminate an XMPP stream, but doesn't always make a clear statement which one to take. This can lead to faulty implementations. In particular, closing a stream that hasn't 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. Note: The recommendation described herein has been incorporated into rfc3920bis.

2. How to Close an Idle Stream

2.1 Handshake Stream Shutdown

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

 </stream:stream> 
then wait for the other entity to close its stream, like this:

 </stream:stream> 
and shut down the underlying TCP connection.

This will ensure that, should the other entity have transmitted any data, it will arrive and be processed before the TCP connection is terminated.

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.

On the outgoing TCP connection you 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.

2.2 Handshake Failure

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.

3. Conclusion

Please update your implementations to use the 'Handshake Stream Shutdown' strategy when shutting down streams you no longer need.

Even not to shut down idle streams at all is a better strategy than to shut them down by creating an error condition, so if your application has no necessity for shutting down idle connections, just don't do it.

4. Security Considerations

This proposal introduces no new security aspects.

5. IANA Considerations

This proposal requires no interaction with the Internet Assigned Numbers Authority (IANA) [3].

6. XMPP Registrar Considerations

This proposal requires no interaction with the XMPP Registrar [4].


Notes

1. RFC 3920: Extensible Messaging and Presence Protocol (XMPP): Core <http://www.ietf.org/rfc/rfc3920.txt>.

2. rfc3921bis: proposed revisions to Extensible Messaging and Presence Protocol (XMPP): Core <http://www.ietf.org/internet-drafts/draft-saintandre-rfc3920bis-00.txt>. (work in progress)

3. The Internet Assigned Numbers Authority (IANA) is the central coordinator for the assignment of unique parameter values for Internet protocols, such as port numbers and URI schemes. For further information, see <http://www.iana.org/>.

4. The XMPP Registrar maintains a list of reserved protocol namespaces as well as registries of parameters used in the context of XMPP extension protocols approved by the Jabber Software Foundation. For further information, see <http://www.xmpp.org/registrar/>.


Revision History

Version 0.1 (2006-07-26)

Initial version.

(psa)

Version 0.0.2 (2006-06-30)

Second draft. (cvl)

Version 0.0.1 (2006-05-31)

First draft. (cvl)


END