buffet: Fix constant retries in XMPP on authorization failure

When XMPP channel is rejected due to invalid credentials, we did not
close the channel stream properly after server had sent "</stream:stream>
element which lead to numerous stream tear-down requests from the server.

Once we receive a stream closed request from the server, we must close
the actual stream/socket immediately.

BUG=brillo:1215
TEST=`FEATURES=test emerge-link buffet`
     Test on the device.

Change-Id: I924e72cd3e647bedf6e3138b55aed146259d52f1
Reviewed-on: https://chromium-review.googlesource.com/281392
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/notification/xmpp_channel.cc b/buffet/notification/xmpp_channel.cc
index fbe2f95..bf9e0b9 100644
--- a/buffet/notification/xmpp_channel.cc
+++ b/buffet/notification/xmpp_channel.cc
@@ -121,6 +121,7 @@
 
 void XmppChannel::OnStreamEnd(const std::string& node_name) {
   VLOG(2) << "XMPP stream ended: " << node_name;
+  Stop();
   if (IsConnected()) {
     // If we had a fully-established connection, restart it now.
     // However, if the connection has never been established yet (e.g.
@@ -344,7 +345,7 @@
 }
 
 void XmppChannel::WaitForMessage() {
-  if (read_pending_)
+  if (read_pending_ || !stream_)
     return;
 
   chromeos::ErrorPtr error;