diff --git a/CHANGES/8267.doc.rst b/CHANGES/8267.doc.rst new file mode 100644 index 00000000000..69f11d37560 --- /dev/null +++ b/CHANGES/8267.doc.rst @@ -0,0 +1 @@ +Added a note about canceling tasks to avoid delaying server shutdown -- by :user:`Dreamsorcerer`. diff --git a/docs/web_advanced.rst b/docs/web_advanced.rst index 3549a5c7e36..d2ba3013e30 100644 --- a/docs/web_advanced.rst +++ b/docs/web_advanced.rst @@ -952,6 +952,14 @@ steps 4 and 7). :ref:`cleanup contexts`. 7. Cancel any remaining tasks and wait on them to complete. +.. note:: + + When creating new tasks in a handler which _should_ be cancelled on server shutdown, + then it is important to keep track of those tasks and explicitly cancel them in a + :attr:`Application.on_shutdown` callback. As we can see from the above steps, + without this the server will wait on those new tasks to complete before it continues + with server shutdown. + Websocket shutdown ^^^^^^^^^^^^^^^^^^