libweave: Crash in XMPP ping when there is no XMPP connection
When there is no active XMPP connection to the server and ping timer
fires, we try to send a ping request to the server, but there is no
socket stream (nullptr) and buffet crashes in XmppChannel::SendMessage().
When XmppChannel::PingServer() is called with the XMPP channel in
"not connected" state, it means only that a network connectivity change
notification has arrived (because the regular ping will be disabled
until we re-establish XMPP connection). In case PingServer is called
with no XMPP connection established, restart XMPP channel and try to
connect to the server.
BUG=brillo:1237
TEST=`FEATURES=test emerge-link buffet`
Deployed on the device and observed buffet while fiddling with network with
`while true; do echo up; ifconfig eth0 up; sleep 90; echo down;ifconfig eth0 down; sleep 90; done`
Change-Id: I26e799cdde078e20a28ed92ba654073131c1daa8
Reviewed-on: https://chromium-review.googlesource.com/284002
Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
Reviewed-by: Vitaly Buka <vitalybuka@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/libweave/src/notification/xmpp_channel.cc b/libweave/src/notification/xmpp_channel.cc
index 542ad61..c7bc35b 100644
--- a/libweave/src/notification/xmpp_channel.cc
+++ b/libweave/src/notification/xmpp_channel.cc
@@ -311,6 +311,7 @@
}
void XmppChannel::SendMessage(const std::string& message) {
+ CHECK(stream_) << "No XMPP socket stream available";
if (write_pending_) {
queued_write_data_ += message;
return;
@@ -486,6 +487,12 @@
void XmppChannel::PingServer(base::TimeDelta timeout) {
VLOG(1) << "Sending XMPP ping";
+ if (!IsConnected()) {
+ LOG(WARNING) << "XMPP channel is not connected";
+ Restart();
+ return;
+ }
+
// Send an XMPP Ping request as defined in XEP-0199 extension:
// http://xmpp.org/extensions/xep-0199.html
iq_stanza_handler_->SendRequestWithCustomTimeout(