Skip to content

Touchup Failure #2643

@rmorshea

Description

@rmorshea

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When running Sanic as an ASGI application in a test suite where apps are repeatedly started and shutdown, Sanic's touchup logic fails with a KeyError.

Traceback (most recent call last):
  File "/home/ryan/Repositories/idom-team/idom/venv/lib/python3.10/site-packages/sanic/asgi.py", line 89, in __call__
    await self.startup()
  File "/home/ryan/Repositories/idom-team/idom/venv/lib/python3.10/site-packages/sanic/asgi.py", line 60, in startup
    await self.asgi_app.sanic_app._startup()
  File "/home/ryan/Repositories/idom-team/idom/venv/lib/python3.10/site-packages/sanic/app.py", line 1572, in _startup
    TouchUp.run(self)
  File "/home/ryan/Repositories/idom-team/idom/venv/lib/python3.10/site-packages/sanic/touchup/service.py", line 24, in run
    modified = BaseScheme.build(method, module_globals, app)
  File "/home/ryan/Repositories/idom-team/idom/venv/lib/python3.10/site-packages/sanic/touchup/schemes/base.py", line 38, in build
    return exec_locals[method.__name__]
KeyError: 'read'

Here are some notable facts:

  1. This problem does not exist in the last version (v22.9.1).
  2. The exact KeyError is random, sometimes its read, but other times it could be something completely different.
  3. The first usages of Sanic works fine. It's the next usages that fails in this way.
  4. The server is being run with uvicorn.

Code snippet

I haven't had time to create a truly isolated example. However, if you install the following:

pip install "idom[sanic,testing]==0.42.0" "uvicorn[standard]==0.20.0"

You can reproduce the error I'm seeing with the following code under sanic==22.12.0:

from asyncio import run
from idom.testing import BackendFixture
from idom.backend import sanic as sanic_backend

async def main():
    async with BackendFixture(implementation=sanic_backend):
        ...

    async with BackendFixture(implementation=sanic_backend):
        ...

run(main())

As mentioned above, running this same code under sanic==22.9.1 works just fine.

Expected Behavior

I should be able to start and stop Sanic servers multiple times without error.

How do you run Sanic?

ASGI

Operating System

Linux (Ubuntu)

Sanic Version

22.12.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy