-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(mobile): sync issue due to time mismatch #4659
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idk if this solves the problem either. The issue is the database may be in a different timezone than the server still. Really we should just send accurate timestamps with timezones
@@ -4,6 +4,7 @@ import { extname } from 'node:path'; | |||
import pkg from 'src/../../package.json'; | |||
|
|||
export const AUDIT_LOG_MAX_DURATION = Duration.fromObject({ days: 100 }); | |||
export const AUDIT_LOG_CLEANUP_DURATION = Duration.fromObject({ days: 101 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? Is this an attempt to resolve a potential issue with time differences between the server and the database?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. it's simply being cautious. keep stuff for 1 day longer than needed if everything works perfect with the machine clocks and timezones
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While that sounds reasonable, I'd much rather be accurate. If we were accurately requesting the change log, this would be unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true. better safe than sorry for now?
dates between app/server are now always in UTC; the server and datebase use |
When we serialize a date and send it over json we're already using the ISO 8601 which is a timezone aware representation of the date and time. If this was passed along correctly to the database everything would be fine, so something is obviously not working correctly. My suspicion is TypeORM is adjusting the time, since JS Dates are only internally stored as numbers and have no sense of timezones. I believe it is offsetting it (incorrectly) to UTC. https://github.com/typeorm/typeorm/blob/master/src/util/DateUtils.ts#L45-L80. |
I see, typeORM doing random stuff again. |
A bigger change I am thinking about is switching to luxon date objects, to which you can do with custom type parsers. I wonder if we left it as a raw string if that would fix this endpoint at least. |
We mount |
Right if local time is the same it is never an issue. It should not be a requirement that the client, server, and database are on the same timezone though. I'm guessing this can be reproduced by having the client and server on different timezones. |
Hi Fynn, do you think we still need this PR? |
Yeah, it's still an issue. I'll rebase and make some changes. |
f08c482
to
eeaa67d
Compare
eeaa67d
to
4ce3676
Compare
rebased and made sure the app always uses the server time when possible So, this PR guards against sync issues originating from time divergence between client and server, e.g. due clock resets or timezone changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine merging it as is. I think we still need to look at how dates get translated between the API body, server, and database, especially when the server and database are in different timezones, but this can be used in the meantime.
Deploying with
|
Latest commit: |
d8413ea
|
Status: | ✅ Deploy successful! |
Preview URL: | https://668752b9.immich.pages.dev |
Branch Preview URL: | https://dev-fix-sync-time-mismatch.immich.pages.dev |
Superseded by #9100 and others |
Currently, the app can get sync issues because of a time mismatch between server and client. This can both occur due to timezone changes or simply wrong clocks.
With this PR, the client retrieves the time for the next sync request from the server, thus solving the issue.