From de7ae358b7b61d6d82e5fe17d0a790ff027cdc53 Mon Sep 17 00:00:00 2001 From: Roman Podoliaka Date: Wed, 15 Feb 2017 16:47:42 +0200 Subject: [PATCH] Make eventlet hub use a monotonic clock If system time is adjusted first forward and then backward while a nova service is running (e.g. nova-compute), then there is a high probability, that periodic tasks will stop for the duration of time the system clock was adjusted backward. This was supposed to be fixed by the following patch to oslo.service https://review.openstack.org/#/c/286838/ , but the order of imports in unit tests and production code is different, so nova services end up starting with the default eventlet hub, that does not use a monotonic clock and, thus, is affected by changes of system time. Testing this is problematic, as it's a subject of imports order and is not reproduced in functional or unit tests (oslo_service is always imported earlier than eventlet hub is initialized, so it just does "the right thing"). The alternative is to make an assertion when services start. Closes-Bug: #1510234 Change-Id: I110cf31ad2a0c74a0cf30ec08bd94d3a56727b39 (cherry picked from commit a7505ee648b22f5827117bcc1192b5654c29cf9c) --- nova/__init__.py | 5 +++++ nova/service.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/nova/__init__.py b/nova/__init__.py index 21403ab570ac..228c89d33dce 100644 --- a/nova/__init__.py +++ b/nova/__init__.py @@ -27,4 +27,9 @@ import os os.environ['EVENTLET_NO_GREENDNS'] = 'yes' +# NOTE(rpodolyaka): import oslo_service first, so that it makes eventlet hub +# use a monotonic clock to avoid issues with drifts of system time (see +# LP 1510234 for details) +import oslo_service # noqa + import eventlet # noqa diff --git a/nova/service.py b/nova/service.py index 01dceb5107a5..578a5a0ba483 100644 --- a/nova/service.py +++ b/nova/service.py @@ -95,6 +95,17 @@ def setup_profiler(binary, host): LOG.info(_LI("OSProfiler is enabled.")) +def assert_eventlet_uses_monotonic_clock(): + import eventlet.hubs as hubs + import monotonic + + hub = hubs.get_hub() + if hub.clock is not monotonic.monotonic: + raise RuntimeError( + 'eventlet hub is not using a monotonic clock - ' + 'periodic tasks will be affected by drifts of system time.') + + class Service(service.Service): """Service object for binaries running on hosts. @@ -136,6 +147,8 @@ class Service(service.Service): } def start(self): + assert_eventlet_uses_monotonic_clock() + verstr = version.version_string_with_package() LOG.info(_LI('Starting %(topic)s node (version %(version)s)'), {'topic': self.topic, 'version': verstr})