summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2011-02-17 19:56:29 -0500
committerEliot Horowitz <eliot@10gen.com>2011-02-17 19:56:29 -0500
commita1810524d6ecd22250b97369c58a9d2bd090702e (patch)
treedcb3c982e364e7476a891acd025c02debc4244f4
parentde11476677e159fd6043b803c03a32d1d8e67332 (diff)
downloadmongo-a1810524d6ecd22250b97369c58a9d2bd090702e.tar.gz
detect clock skew in DistributedLock SERVER-2584
-rw-r--r--client/distlock.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/client/distlock.cpp b/client/distlock.cpp
index 05e54c08d0c..1e4da211271 100644
--- a/client/distlock.cpp
+++ b/client/distlock.cpp
@@ -135,7 +135,17 @@ namespace mongo {
return false;
}
- unsigned long long elapsed = jsTime() - lastPing["ping"].Date(); // in ms
+ unsigned long long now = jsTime();
+ unsigned long long pingTime = lastPing["ping"].Date();
+
+ if ( now < pingTime ) {
+ // clock skew
+ warning() << "dist_lock has detected clock skew of " << ( pingTime - now ) << "ms" << endl;
+ conn.done();
+ return false;
+ }
+
+ unsigned long long elapsed = now - pingTime;
elapsed = elapsed / ( 1000 * 60 ); // convert to minutes
if ( elapsed <= _takeoverMinutes ){