A stream is closed by sending a closing </stream>
tag. After the closing stream tag is sent, no more data should be sent on the stream (even in response to data received from the other party). Before closing the connection, the sending entity should wait for a response </stream>
tag to give the other party time to send any outstanding data and should time out (and terminate the underlying TCP connection[s]) if a closing stream tag is not received within a chosen amount of time.
</stream:stream>
If the stream is encrypted with TLS, the parties must cleanly terminate TLS by sending a TLS close_notify
alert and receiving one in response. Your TLS library probably does this for you.