summaryrefslogtreecommitdiffstats
path: root/remoting/host
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/host')
-rw-r--r--remoting/host/heartbeat_sender.cc26
-rw-r--r--remoting/host/heartbeat_sender.h2
2 files changed, 26 insertions, 2 deletions
diff --git a/remoting/host/heartbeat_sender.cc b/remoting/host/heartbeat_sender.cc
index 16ec93e..e061acc 100644
--- a/remoting/host/heartbeat_sender.cc
+++ b/remoting/host/heartbeat_sender.cc
@@ -40,6 +40,8 @@ const char kExpectedSequenceIdTag[] = "expected-sequence-id";
const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes.
const int64 kResendDelayMs = 10 * 1000; // 10 seconds.
+const int64 kResendDelayOnHostNotFoundMs = 10 * 1000; // 10 seconds.
+const int kMaxResendOnHostNotFoundCount = 12; // 2 minutes (12 x 10 seconds).
const int kExitCodeHostIdInvalid = 100;
@@ -55,7 +57,9 @@ HeartbeatSender::HeartbeatSender(
interval_ms_(kDefaultHeartbeatIntervalMs),
sequence_id_(0),
sequence_id_was_set_(false),
- sequence_id_recent_set_num_(0) {
+ sequence_id_recent_set_num_(0),
+ heartbeat_succeeded_(false),
+ failed_startup_heartbeat_count_(0) {
DCHECK(signal_strategy_);
DCHECK(key_pair_);
@@ -114,10 +118,26 @@ void HeartbeatSender::ProcessResponse(IqRequest* request,
response->FirstNamed(QName(buzz::NS_CLIENT, kErrorTag));
if (error_element) {
if (error_element->FirstNamed(QName(buzz::NS_STANZA, kNotFoundTag))) {
+ LOG(ERROR) << "Received error: Host ID not found";
+ // If the host was registered immediately before it sends a heartbeat,
+ // then server-side latency may prevent the server recognizing the
+ // host ID in the heartbeat. So even if all of the first few heartbeats
+ // get a "host ID not found" error, that's not a good enough reason to
+ // exit.
+ failed_startup_heartbeat_count_++;
+ if (!heartbeat_succeeded_ && (failed_startup_heartbeat_count_ <=
+ kMaxResendOnHostNotFoundCount)) {
+ timer_resend_.Start(FROM_HERE,
+ base::TimeDelta::FromMilliseconds(
+ kResendDelayOnHostNotFoundMs),
+ this,
+ &HeartbeatSender::ResendStanza);
+ return;
+ }
// TODO(lambroslambrou): Trigger an application-defined callback to
// shut down the host properly, instead of just exiting here
// (http://crbug.com/112160).
- LOG(ERROR) << "Received error: Host ID invalid";
+ LOG(ERROR) << "Exit: Host ID not found";
exit(kExitCodeHostIdInvalid);
}
}
@@ -127,6 +147,8 @@ void HeartbeatSender::ProcessResponse(IqRequest* request,
return;
}
+ heartbeat_succeeded_ = true;
+
// This method must only be called for error or result stanzas.
DCHECK_EQ(std::string(buzz::STR_RESULT), type);
diff --git a/remoting/host/heartbeat_sender.h b/remoting/host/heartbeat_sender.h
index 92425fe..f2f5a47 100644
--- a/remoting/host/heartbeat_sender.h
+++ b/remoting/host/heartbeat_sender.h
@@ -122,6 +122,8 @@ class HeartbeatSender : public SignalStrategy::Listener {
int sequence_id_;
bool sequence_id_was_set_;
int sequence_id_recent_set_num_;
+ bool heartbeat_succeeded_;
+ int failed_startup_heartbeat_count_;
DISALLOW_COPY_AND_ASSIGN(HeartbeatSender);
};