Skip to content

Commit 31393be

Browse files
committed
make an edge case of server time sync more robust
- no reported issues like this, but we might as well make it better and more careful
1 parent 861ded7 commit 31393be

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/packages/frontend/client/time.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,18 @@ export class TimeClient {
112112
// That's annoying -- time is not marching forward... let's fake it until it does.
113113
t = new Date(last.valueOf() + 1);
114114
}
115-
if (this.clock_skew_ms) {
116-
// We have synced the clock once successfully, so we now ensure the time is increasing.
115+
if (
116+
this.last_pong != null &&
117+
Date.now() - this.last_pong.local.valueOf() < 5 * this.ping_interval_ms
118+
) {
119+
// We have synced the clock **recently successfully**, so
120+
// we now ensure the time is increasing.
117121
// This first sync should happen with ms of the user connecting.
122+
// We do NOT trust if the sync was a long time ago, e.g., due to
123+
// a long network outage or laptop suspend/resume.
118124
this.last_server_time = t;
125+
} else {
126+
delete this.last_server_time;
119127
}
120128
return t;
121129
}

src/packages/util/smc-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* autogenerated by the update_version script */
2-
exports.version=1727277632;
2+
exports.version=1727734946;

0 commit comments

Comments
 (0)