Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from Feb 8, 2022
Merged

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

merged 5 commits into from Feb 8, 2022

Conversation

SaidBySolo
Copy link
Member

@SaidBySolo SaidBySolo commented Jan 17, 2022

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
Copy link

codecov bot commented Jan 17, 2022

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.

sanic/app.py Outdated Show resolved Hide resolved
@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
@ahopkins
Copy link
Member

Can you add a unit test?

@SaidBySolo
Copy link
Member Author

SaidBySolo commented Jan 18, 2022

@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
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.

None yet

3 participants