Skip to content

Commit

Permalink
Small fix to help prevent falsely reporting clock skew when the
Browse files Browse the repository at this point in the history
DB is under heavy load.

There is a semantic difference between how `NOW()` and `SYSDATE()` work
([docs](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_sysdate)),
mainly being that `NOW()` captures the time when the query begins
execution and can be manipulated by some variables (generally for
testing purposes) while `SYSDATE()` returns the time the function is
executed (i.e. closer to when it is returned to the client) and cannot
be manipulated.

GitOrigin-RevId: 298fb59bc79e5f6b3fed96017bd2cdd2f7a6b279
  • Loading branch information
mpeyper authored and svc-squareup-copybara committed Feb 12, 2025
1 parent 7ad70a9 commit 4d04cbe
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class HibernateHealthCheck(
val databaseInstant = try {
val sessionFactory = sessionFactoryService.get().sessionFactory
sessionFactory.openSession().use { session ->
session.createNativeQuery("SELECT NOW()").uniqueResult() as Timestamp
session.createNativeQuery("SELECT SYSDATE()").uniqueResult() as Timestamp
}.toInstant()
} catch (e: Exception) {
logger.error(e) { "error performing hibernate health check" }
Expand Down

0 comments on commit 4d04cbe

Please sign in to comment.