django / asgiref

ASGI specification and utilities
https://asgi.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
1.46k stars 207 forks source link

Task was destroyed but it is pending! #450

Open mtelka opened 5 months ago

mtelka commented 5 months ago

While running tests for asgiref 3.8.0 I see following unexpected lines at the end of the test report:

======================== 71 passed, 1 xfailed in 12.82s ========================
Task was destroyed but it is pending!
task: <Task pending name='Task-33' coro=<StatelessServer.application_checker() running at $(BUILD_DIR)/asgiref/server.py:136> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x7fffadd838e0>()]>>
Task was destroyed but it is pending!
task: <Task pending name='Task-55' coro=<server.<locals>.app() running at $(BUILD_DIR)/tests/test_server.py:81> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='Task-57' coro=<server.<locals>.app() running at $(BUILD_DIR)/tests/test_server.py:81> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='Task-59' coro=<server.<locals>.app() running at $(BUILD_DIR)/tests/test_server.py:81> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='Task-61' coro=<server.<locals>.app() running at $(BUILD_DIR)/tests/test_server.py:81> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='Task-63' coro=<server.<locals>.app() running at $(BUILD_DIR)/tests/test_server.py:81> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='Task-65' coro=<server.<locals>.app() running at $(BUILD_DIR)/tests/test_server.py:81> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='Task-67' coro=<server.<locals>.app() running at $(BUILD_DIR)/tests/test_server.py:81> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='Task-69' coro=<server.<locals>.app() running at $(BUILD_DIR)/tests/test_server.py:81> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='Task-71' coro=<server.<locals>.app() running at $(BUILD_DIR)/tests/test_server.py:81> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='Task-73' coro=<server.<locals>.app() running at $(BUILD_DIR)/tests/test_server.py:81> wait_for=<Future cancelled>>
Task was destroyed but it is pending!
task: <Task pending name='Task-75' coro=<server.<locals>.app() running at $(BUILD_DIR)/tests/test_server.py:81> wait_for=<Future cancelled>>
  py39: OK (13.70=setup[0.06]+cmd[13.65] seconds)
  congratulations :) (14.51 seconds)
carltongibson commented 5 months ago

Yes, this is an issue with the structure of StatelessServer, such that it doesn't clean up the app tasks in the test cases.

You can see the discussion here for some more detail

It would be a good clean up if you'd like to take it on.