From 3f3060ebeda9e6d6087241c4b5ab78eee8735a69 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Thu, 8 May 2025 17:30:56 +0200 Subject: [PATCH] misc/capnproto: patch to avoid monotonic time checks From time to time, our KVM's CI machine clock goes in a weird direction during NixOS tests, this is known on certain hardware, e.g. macOS, where the check is disabled. Cap'n'Proto removed the check everywhere now. Fixes fj#754. We can remove the patch once it hits a stable version of Cap'n'Proto. Change-Id: I4c9be5061c3b244f601486a8ac4521dff44ceb92 Signed-off-by: Raito Bezarius --- ...capnproto-monotonic-clocks-are-a-lie.patch | 47 +++++++++++++++++++ misc/capnproto.nix | 2 + misc/pre-commit.nix | 6 ++- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 misc/capnproto-monotonic-clocks-are-a-lie.patch diff --git a/misc/capnproto-monotonic-clocks-are-a-lie.patch b/misc/capnproto-monotonic-clocks-are-a-lie.patch new file mode 100644 index 000000000..5810214cb --- /dev/null +++ b/misc/capnproto-monotonic-clocks-are-a-lie.patch @@ -0,0 +1,47 @@ +From 11375442cf591f055ca95902f27c68b0e983d371 Mon Sep 17 00:00:00 2001 +From: Fabio Rossetto +Date: Thu, 8 May 2025 18:18:10 +0200 +Subject: [PATCH] Remove check for monotonic time + +The check was disabled on Mac, but in #2261 it was reported also on +Linux. At this point, it makes more sense to remove the KJ_REQUIRE for +monotonicity alltogether. + +Backport of the original PR #2296 to v1.0.2. + +Signed-off-by: Raito Bezarius +Co-authored-by: Raito Bezarius +--- + c++/src/kj/timer.c++ | 15 ++++++--------- + 1 file changed, 6 insertions(+), 9 deletions(-) + +diff --git a/c++/src/kj/timer.c++ b/c++/src/kj/timer.c++ +index e5cd2648..a659e5d0 100644 +--- a/c++/src/kj/timer.c++ ++++ b/c++/src/kj/timer.c++ +@@ -110,16 +110,13 @@ Maybe TimerImpl::timeoutToNextEvent(TimePoint start, Duration unit, ui + } + + void TimerImpl::advanceTo(TimePoint newTime) { +- // On Macs running an Intel processor, it has been observed that clock_gettime +- // may return non monotonic time, even when CLOCK_MONOTONIC is used. +- // This workaround is to avoid the assert triggering on these machines. +- // See also https://github.com/capnproto/capnproto/issues/1693 +-#if __APPLE__ && defined(__x86_64__) ++ // It has been observed that clock_gettime may return non monotonic time, ++ // even when CLOCK_MONOTONIC is used. ++ // We use std::max to guard against this rare issue. ++ // - on Mac: https://github.com/capnproto/capnproto/issues/1693 ++ // - on Linux: https://github.com/capnproto/capnproto/issues/2261 ++ + time = std::max(time, newTime); +-#else +- KJ_REQUIRE(newTime >= time, "can't advance backwards in time") { return; } +- time = newTime; +-#endif + + for (;;) { + auto front = impl->timers.begin(); +-- +2.49.0 + diff --git a/misc/capnproto.nix b/misc/capnproto.nix index 27bd8920a..4100290de 100644 --- a/misc/capnproto.nix +++ b/misc/capnproto.nix @@ -38,6 +38,8 @@ stdenv.mkDerivation rec { patches = [ # backport of https://github.com/capnproto/capnproto/pull/1810 ./capnproto-promise-nodiscard.patch + # backport of https://github.com/capnproto/capnproto/pull/2296 + ./capnproto-monotonic-clocks-are-a-lie.patch ]; nativeBuildInputs = [ cmake ]; diff --git a/misc/pre-commit.nix b/misc/pre-commit.nix index 6b9449bd9..2f9ecde4a 100644 --- a/misc/pre-commit.nix +++ b/misc/pre-commit.nix @@ -51,6 +51,7 @@ pre-commit-run { excludes = [ "\\.drv$" "^tests/functional/lang/" + ''\.patch$'' ]; }; mixed-line-endings = { @@ -107,7 +108,10 @@ pre-commit-run { trim-trailing-whitespace = { enable = true; stages = [ "pre-commit" ]; - excludes = [ "^tests/functional/lang/" ]; + excludes = [ + ''^tests/functional/lang/'' + ''\.patch$'' + ]; }; treefmt = { enable = true;