summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsimonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-12 03:56:39 +0000
committersimonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-12 03:56:39 +0000
commit67d948d0d66742bbdae8529f4d1b0c9d19fa4ca3 (patch)
tree41fc2eed3324c71657f0ac6fb16cbfcf0b3f58f8 /remoting
parent671ad89940092ae7025194bfe14665ab0e002cfd (diff)
downloadchromium_src-67d948d0d66742bbdae8529f4d1b0c9d19fa4ca3.zip
chromium_src-67d948d0d66742bbdae8529f4d1b0c9d19fa4ca3.tar.gz
chromium_src-67d948d0d66742bbdae8529f4d1b0c9d19fa4ca3.tar.bz2
[Chromoting] Stop the host from exiting just because the first few heartbeats return 'host not found'.
BUG=122413 Review URL: http://codereview.chromium.org/10052004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131921 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-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);
};