From 54d35d7358934bf60e11dd661f7045002c546e5f Mon Sep 17 00:00:00 2001 From: l <> Date: Wed, 23 Jan 2019 22:09:08 +0800 Subject: [PATCH 1/2] Fix #1965: About gunicorn [CRITICAL] Worker Timeout --- gunicorn/arbiter.py | 2 +- gunicorn/workers/workertmp.py | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index 7eaa2c17..f7f86f00 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -494,7 +494,7 @@ class Arbiter(object): workers = list(self.WORKERS.items()) for (pid, worker) in workers: try: - if time.time() - worker.tmp.last_update() <= self.timeout: + if time.monotonic() - worker.tmp.last_update() <= self.timeout: continue except (OSError, ValueError): continue diff --git a/gunicorn/workers/workertmp.py b/gunicorn/workers/workertmp.py index 22aaef34..66defe94 100644 --- a/gunicorn/workers/workertmp.py +++ b/gunicorn/workers/workertmp.py @@ -4,6 +4,7 @@ # See the NOTICE for more information. import os +import time import platform import tempfile @@ -35,14 +36,12 @@ class WorkerTmp(object): os.close(fd) raise - self.spinner = 0 - def notify(self): - self.spinner = (self.spinner + 1) % 2 - os.fchmod(self._tmp.fileno(), self.spinner) + new_time = time.monotonic() + os.utime(self._tmp.name, (new_time, new_time)) def last_update(self): - return os.fstat(self._tmp.fileno()).st_ctime + return os.fstat(self._tmp.fileno()).st_mtime def fileno(self): return self._tmp.fileno() From 2a0433e7ed7185266f1430d774d15474562c0403 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Sun, 17 Feb 2019 14:37:37 +0800 Subject: [PATCH 2/2] Update gunicorn/workers/workertmp.py Co-Authored-By: skytoup <875766917@qq.com> --- gunicorn/workers/workertmp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gunicorn/workers/workertmp.py b/gunicorn/workers/workertmp.py index 66defe94..604c759c 100644 --- a/gunicorn/workers/workertmp.py +++ b/gunicorn/workers/workertmp.py @@ -38,7 +38,7 @@ class WorkerTmp(object): def notify(self): new_time = time.monotonic() - os.utime(self._tmp.name, (new_time, new_time)) + os.utime(self._tmp.fileno(), (new_time, new_time)) def last_update(self): return os.fstat(self._tmp.fileno()).st_mtime