@@ -355,6 +355,25 @@ def _spawn_as_child(self, filename, argv):
355
355
options .write (2 , "supervisor: child process was not spawned\n " )
356
356
options ._exit (127 ) # exit process with code for spawn failure
357
357
358
+ def _check_and_adjust_for_system_clock_rollback (self , test_time ):
359
+ """
360
+ Check if system clock has rolled backward beyond test_time. If so, set
361
+ affected timestamps to test_time.
362
+ """
363
+ if self .state == ProcessStates .STARTING :
364
+ if test_time < self .laststart :
365
+ self .laststart = test_time ;
366
+ if self .delay > 0 and test_time < self .delay - self .config .startsecs :
367
+ self .delay = test_time + self .config .startsecs
368
+ elif self .state == ProcessStates .STOPPING :
369
+ if test_time < self .laststopreport :
370
+ self .laststopreport = test_time ;
371
+ if self .delay > 0 and test_time < self .delay - self .config .stopwaitsecs :
372
+ self .delay = test_time + self .config .stopwaitsecs
373
+ elif self .state == ProcessStates .BACKOFF :
374
+ if self .delay > 0 and test_time < self .delay - self .backoff :
375
+ self .delay = test_time + self .backoff
376
+
358
377
def stop (self ):
359
378
""" Administrative stop """
360
379
self .administrative_stop = True
@@ -366,10 +385,7 @@ def stop_report(self):
366
385
if self .state == ProcessStates .STOPPING :
367
386
now = time .time ()
368
387
369
- if now < self .laststopreport :
370
- # The system clock appears to have moved backward
371
- # Reset self.laststopreport to current system time
372
- self .laststopreport = now ;
388
+ self ._check_and_adjust_for_system_clock_rollback (now )
373
389
374
390
if now > (self .laststopreport + 2 ): # every 2 seconds
375
391
self .config .options .logger .info (
@@ -610,6 +626,8 @@ def transition(self):
610
626
now = time .time ()
611
627
state = self .state
612
628
629
+ self ._check_and_adjust_for_system_clock_rollback (now )
630
+
613
631
logger = self .config .options .logger
614
632
615
633
if self .config .options .mood > SupervisorStates .RESTARTING :
@@ -628,28 +646,13 @@ def transition(self):
628
646
# STOPPED -> STARTING
629
647
self .spawn ()
630
648
elif state == ProcessStates .BACKOFF :
631
- if self .delay > 0 and now < self .delay - self .backoff :
632
- # The system clock appears to have moved backward
633
- # Reset self.delay accordingly
634
- self .delay = now + self .backoff
635
-
636
649
if self .backoff <= self .config .startretries :
637
650
if now > self .delay :
638
651
# BACKOFF -> STARTING
639
652
self .spawn ()
640
653
641
654
processname = as_string (self .config .name )
642
655
if state == ProcessStates .STARTING :
643
- if now < self .laststart :
644
- # The system clock appears to have moved backward
645
- # Reset self.laststart to current system time
646
- self .laststart = now ;
647
-
648
- if self .delay > 0 and now < self .delay - self .config .startsecs :
649
- # The system clock appears to have moved backward
650
- # Reset self.delay accordingly
651
- self .delay = now + self .config .startsecs
652
-
653
656
if now - self .laststart > self .config .startsecs :
654
657
# STARTING -> RUNNING if the proc has started
655
658
# successfully and it has stayed up for at least
@@ -673,11 +676,6 @@ def transition(self):
673
676
logger .info ('gave up: %s %s' % (processname , msg ))
674
677
675
678
elif state == ProcessStates .STOPPING :
676
- if self .delay > 0 and now < self .delay - self .config .stopwaitsecs :
677
- # The system clock appears to have moved backward
678
- # Reset self.delay accordingly
679
- self .delay = now + self .config .stopwaitsecs
680
-
681
679
time_left = self .delay - now
682
680
if time_left <= 0 :
683
681
# kill processes which are taking too long to stop with a final
0 commit comments