Skip to content

Commit

Permalink
feat!: enable timeout
Browse files Browse the repository at this point in the history
 default timeout settings is 5 min, same as Cloud run;
 change default behavior from multi-threads to multi-workesr to avoid zombie timeout settings;
 allow user customization to workers/threads by assigning env var;
 noted that timeout won't work when #thread > 1.
  • Loading branch information
chujchen committed Feb 12, 2024
1 parent e175553 commit 1fb6ff0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/functions_framework/_http/gunicorn.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ class GunicornApplication(gunicorn.app.base.BaseApplication):
def __init__(self, app, host, port, debug, **options):
self.options = {
"bind": "%s:%s" % (host, port),
"workers": 1,
"threads": (os.cpu_count() or 1) * 4,
"timeout": 0,
"workers": os.environ.get("WORKERS", (os.cpu_count() or 1) * 4),
"threads": os.environ.get("THREADS", 1),
"timeout": os.environ.get("CLOUD_RUN_TIMEOUT_SECONDS", 300),
"loglevel": "error",
"limit_request_line": 0,
}
self.options.update(options)
self.app = app

super().__init__()

def load_config(self):
Expand Down

0 comments on commit 1fb6ff0

Please sign in to comment.