Skip to content

fix(tasks): newly assigned None in registry#2381

Merged
ahopkins merged 5 commits into
sanic-org:mainfrom
SaidBySolo:set_name_when_registered
Feb 8, 2022
Merged

fix(tasks): newly assigned None in registry#2381
ahopkins merged 5 commits into
sanic-org:mainfrom
SaidBySolo:set_name_when_registered

Conversation

@SaidBySolo

@SaidBySolo SaidBySolo commented Jan 17, 2022

Copy link
Copy Markdown
Member

How to reproduce?

from sanic import Sanic
from asyncio import sleep, create_task

app = Sanic(__name__)


async def task():
    while True:
        await sleep(10)


@app.before_server_start
async def dummy_start(app, _):
    app.add_task(create_task(task()), name="Dummy")


@app.before_server_stop
async def dummy_stop(app, _):
    # Raise RuntimeError: dictionary changed size during iteration
    app.purge_tasks()


app.run()

sanic/sanic/app.py

Lines 1273 to 1274 in b8d9914

name = task.get_name()
self._task_registry[name] = None

If a name is not registered during create_task, the following name is obtained as Task-1, so the error that occurred because it is newly assigned has been resolved.

@SaidBySolo SaidBySolo requested a review from a team as a code owner January 17, 2022 12:30
@codecov

codecov Bot commented Jan 17, 2022

Copy link
Copy Markdown

Codecov Report

Merging #2381 (9476754) into main (88bc6d8) will increase coverage by 0.017%.
The diff coverage is 100.000%.

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #2381       +/-   ##
=============================================
+ Coverage   87.090%   87.107%   +0.017%     
=============================================
  Files           60        60               
  Lines         5004      5003        -1     
  Branches       905       905               
=============================================
  Hits          4358      4358               
  Misses         472       472               
+ Partials       174       173        -1     
Impacted Files Coverage Δ
sanic/app.py 89.668% <100.000%> (+0.174%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 88bc6d8...9476754. Read the comment docs.

Comment thread sanic/app.py Outdated
@SaidBySolo SaidBySolo changed the title fix(app): set name when registered fix(tasks): set name when registered Jan 17, 2022
@SaidBySolo SaidBySolo changed the title fix(tasks): set name when registered fix(tasks): newly assigned None in registry Jan 18, 2022
@SaidBySolo SaidBySolo changed the title fix(tasks): newly assigned None in registry fix(tasks): newly assigned None in registry Jan 18, 2022
@SaidBySolo SaidBySolo requested a review from ahopkins January 18, 2022 10:04
@ahopkins

Copy link
Copy Markdown
Member

Can you add a unit test?

@SaidBySolo

SaidBySolo commented Jan 18, 2022

Copy link
Copy Markdown
Member Author

@ahopkins

All tests passed!

I'm not sure if the test I wrote is correct.

@ahopkins ahopkins merged commit 68b654d into sanic-org:main Feb 8, 2022
ChihweiLHBird pushed a commit to ChihweiLHBird/sanic that referenced this pull request Jun 1, 2022
ashleysommer added a commit to ashleysommer/sanic that referenced this pull request Jun 26, 2024
ahopkins added a commit that referenced this pull request Jun 27, 2024
)

* Undo bug introduced by #2381, revert to super() protocol abort behavior.

* Smarter transport stream close() and abort()
Rather than simply calling `abort()` at a set interval after calling `close()`, we implement a mechanism to detect if any data is still in the transport write buffer after close is called, and schedules an async close operation to wait until the transport has finished, or finally calls abort after a reasonable timeout.

* Add GRACEFUL_TCP_CLOSE_TIMEOUT as the timeout param

* Unrelated E721 change

---------

Co-authored-by: Adam Hopkins <adam@amhopkins.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants