Skip to content

Commit 7d70f18

Browse files
committed
fix!: avoid long running process when request timeout
Previously function framework use 0 timeout which is actually "no timeout" restrction. This was causing a problem that when user provides a request timeout to Cloud function, process will still continue and consume resources. In this fix, timeout is enabled; default timeout settings is 5 min, same as Cloud run. To make sure timeout settings will be respected, default settings switched from multi-threads to multi-workers. However, user is still allowed to customize workers/threads by assigning env var. But user need to note that timeout won't work when #thread > 1.
1 parent e175553 commit 7d70f18

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/functions_framework/_http/gunicorn.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ class GunicornApplication(gunicorn.app.base.BaseApplication):
2121
def __init__(self, app, host, port, debug, **options):
2222
self.options = {
2323
"bind": "%s:%s" % (host, port),
24-
"workers": 1,
25-
"threads": (os.cpu_count() or 1) * 4,
26-
"timeout": 0,
24+
"workers": os.environ.get("WORKERS", (os.cpu_count() or 1) * 4),
25+
"threads": os.environ.get("THREADS", 1),
26+
"timeout": os.environ.get("CLOUD_RUN_TIMEOUT_SECONDS", 300),
2727
"loglevel": "error",
2828
"limit_request_line": 0,
2929
}
3030
self.options.update(options)
3131
self.app = app
32+
3233
super().__init__()
3334

3435
def load_config(self):

0 commit comments

Comments
 (0)