Skip to content

Commit 489c917

Browse files
committed
Add additional timeout parameters to StarletteAdapter.
1 parent ad0e1f9 commit 489c917

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

docs/getting-started/changelog.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,14 @@ Changelog
115115

116116
- twitchio.web.StarletteAdapter
117117
- Additions
118-
- Added the ``timeout_keep_alive`` keyword parameter which allows controlling how long ``Starlette/Uvicorn`` will wait to gracefully close.
118+
- Added the ``timeout_graceful_shutdown`` keyword parameter which allows controlling how long ``Starlette/Uvicorn`` will wait to gracefully close.
119+
- Added the ``timeout_keep_alive`` keyword parameter which allows controlling how long ``Uvicorn`` will wait until closing Keep-Alive connections after not receiving any data.
119120

120121
- Bug fixes
121122
- Fixed the redirect URL not allowing HOST/PORT when a custom domain was passed.
122123
- The redirect URL is now determined based on where the request came from.
123124
- Fixed Uvicorn hanging the process when attempting to close the :class:`asyncio.Loop` on **Windows**.
124-
- After a default of ``5 seconds`` Uvicorn will be forced closed if it cannot gracefully close in this time. This time can be changed with the ``timeout_keep_alive`` parameter.
125+
- After a default of ``3 seconds`` Uvicorn will be forced closed if it cannot gracefully close in this time. This time can be changed with the ``timeout_graceful_shutdown`` parameter.
125126
- Now correctly changes the protocol to ``https`` when SSL is used directly on the adapter.
126127

127128
- ext.commands

twitchio/web/starlette_adapter.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ class StarletteAdapter(BaseAdapter, Starlette):
113113
An optional password to decrypt the ssl key, passed to Uvicorn.
114114
ssl_certfile: str | PathLike[str] | None
115115
An optional SSL certificate file, passed to Uvicorn.
116+
timeout_keep_alive: int
117+
An optional :class:`int` which is the maximum amount of time in seconds ``Uvicorn`` should wait before closing
118+
Keep-Alive connections. Defaults to ``5``.
119+
timeout_graceful_shutdown: int
120+
An optional :class:`int` which is the maximum amount of time in seconds ``Uvicorn`` should wait before forcefully
121+
closing. Defaults to ``3``.
116122
117123
Examples
118124
--------
@@ -154,7 +160,11 @@ def __init__(
154160
ssl_keyfile: str | PathLike[str] | None = None,
155161
ssl_keyfile_password: str | None = None,
156162
ssl_certfile: str | PathLike[str] | None = None,
163+
timeout_keep_alive: int = 5,
164+
timeout_graceful_shutdown: int = 3,
157165
) -> None:
166+
self._timeout_keep_alive = timeout_keep_alive
167+
self._timeout_graceful_shutdown = timeout_graceful_shutdown
158168
self._host: str = host or "localhost"
159169
self._port: int = port or 4343
160170

@@ -266,11 +276,11 @@ async def run(self, host: str | None = None, port: int | None = None) -> None:
266276
port=self._port,
267277
log_level="critical",
268278
workers=0,
269-
timeout_graceful_shutdown=3,
279+
timeout_graceful_shutdown=self._timeout_graceful_shutdown,
270280
ssl_keyfile=self.__keyfile,
271281
ssl_keyfile_password=self.__keypass,
272282
ssl_certfile=self.__certfile,
273-
timeout_keep_alive=5,
283+
timeout_keep_alive=self._timeout_keep_alive,
274284
)
275285

276286
self._server = uvicorn.Server(config)

0 commit comments

Comments
 (0)