From dc67eace2456e0e3c34083f3e38318ab26558ad0 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 29 Nov 2021 18:39:07 +0000 Subject: [PATCH] Server: Allow disabling NTP time drift check --- packages/server/src/app.ts | 10 ++++++---- packages/server/src/env.ts | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/server/src/app.ts b/packages/server/src/app.ts index 044680a2c..f0e091986 100644 --- a/packages/server/src/app.ts +++ b/packages/server/src/app.ts @@ -251,12 +251,14 @@ async function main() { appLogger().info(`Starting server v${config().appVersion} (${env}) on port ${config().port} and PID ${process.pid}...`); - const timeDrift = await getDeviceTimeDrift(); - if (Math.abs(timeDrift) > config().maxTimeDrift) { - throw new Error(`The device time drift is ${timeDrift}ms (Max allowed: ${config().maxTimeDrift}ms) - cannot continue as it could cause data loss and conflicts on the sync clients. You may increase env var MAX_TIME_DRIFT to pass the check.`); + if (config().maxTimeDrift) { + const timeDrift = await getDeviceTimeDrift(); + if (Math.abs(timeDrift) > config().maxTimeDrift) { + throw new Error(`The device time drift is ${timeDrift}ms (Max allowed: ${config().maxTimeDrift}ms) - cannot continue as it could cause data loss and conflicts on the sync clients. You may increase env var MAX_TIME_DRIFT to pass the check.`); + } + appLogger().info(`NTP time offset: ${timeDrift}ms`); } - appLogger().info(`NTP time offset: ${timeDrift}ms`); appLogger().info('Running in Docker:', runningInDocker()); appLogger().info('Public base URL:', config().baseUrl); appLogger().info('API base URL:', config().apiBaseUrl); diff --git a/packages/server/src/env.ts b/packages/server/src/env.ts index 2076391cc..d00135d81 100644 --- a/packages/server/src/env.ts +++ b/packages/server/src/env.ts @@ -21,8 +21,8 @@ const defaultEnvValues: EnvVariables = { // milliseconds is normally not an issue unless many clients are modifying // the same note at the exact same time. But past a certain limit, it might // mean the server clock is incorrect and should be fixed, as that could - // result in clients generating many conflicts. - // https://github.com/laurent22/joplin/issues/5738 + // result in clients generating many conflicts. Set to 0 to disable the + // check. https://github.com/laurent22/joplin/issues/5738 MAX_TIME_DRIFT: 100,