Comments (3)
Hi, @emcpow2, thanks for reporting the issue.
I am able to reproduce it, and thanks for making a fix so quickly! I'll be merging it and releasing a new version too
from fastapi-events.
It is easy to reproduce with this minimal app
import asyncio
import random
from fastapi import FastAPI
from fastapi_events.dispatcher import dispatch
from fastapi_events.handlers.local import local_handler
from fastapi_events.middleware import EventHandlerASGIMiddleware
app = FastAPI()
app.add_middleware(EventHandlerASGIMiddleware, handlers=[local_handler])
@app.get("/healthz")
async def healthz():
dispatch("xyz", payload=None)
await asyncio.sleep(random.randint(1, 5))
Running
poetry run uvicorn --loop asyncio --http h11 example.minimal_fastapi_app:app
...
INFO: 127.0.0.1:63106 - "GET /healthz HTTP/1.1" 200 OK
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/Users/e.iskandarov/example/.venv/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 373, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "/Users/e.iskandarov/example/.venv/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
return await self.app(scope, receive, send)
File "/Users/e.iskandarov/example/.venv/lib/python3.8/site-packages/fastapi/applications.py", line 208, in __call__
await super().__call__(scope, receive, send)
File "/Users/e.iskandarov/example/.venv/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
await self.middleware_stack(scope, receive, send)
File "/Users/e.iskandarov/example/.venv/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
raise exc
File "/Users/e.iskandarov/example/.venv/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "/Users/e.iskandarov/example/.venv/lib/python3.8/site-packages/fastapi_events/middleware.py", line 29, in __call__
self._teardown_event_store()
File "/Users/e.iskandarov/example/.venv/lib/python3.8/site-packages/fastapi_events/middleware.py", line 40, in _teardown_event_store
event_store.reset(self._token)
ValueError: <Token var=<ContextVar name='fastapi_context' at 0x106b196d0> at 0x106b89200> was created in a different Context
and executing wrk
to sent requests asynchronously
wrk -c2 -d30s http://127.0.0.1:8000/healthz
Libraries
MacOS 10.14.6
Python 3.8.6
fastapi-events==0.1.1; python_version >= "3.7"
fastapi==0.70.0; python_full_version >= "3.6.1"
uvicorn==0.15.0
uvloop==0.16.0; sys_platform != "win32" and sys_platform != "cygwin" and platform_python_implementation != "PyPy" and python_version >= "3.7"
anyio==3.3.2; python_version >= "3.6" and python_full_version >= "3.6.2"
h11==0.12.0; python_version >= "3.6"
from fastapi-events.
the issue persists with EchoHandler
too
from fastapi-events.
Related Issues (20)
- Add a SNS Handler HOT 2
- Proposal - use asyncio for events management (Supporting Event Chaining) HOT 5
- Add GCP Cloud PubSub handler
- Catching exceptions of dispatched events HOT 1
- Trigger an event at startup HOT 3
- Add OpenTelemetry (OTEL) Support
- Providing AWS Credentials HOT 2
- Events are not received when dispatch() occurs in an asyncio.Task HOT 5
- Add Python 3.11 HOT 1
- Introduces NullHandler
- Support for Depends() HOT 8
- Starlette-Specific Test Cases Failing Since Starlette 0.24
- pydantic v2 import errors HOT 6
- pydantic v2 Warnings: The `dict` method is deprecated; use `model_dump` instead HOT 3
- Register event payload class and event in 1 HOT 8
- Update tox configuration to check compatibility with Python 3.12
- Pydantic models dumped to dict with deprecated method `dict` with pydantic v2 HOT 1
- Do not always dump pydantic models to dict
- docs: Update README with public API HOT 1
- TypeError with Synchronous Function in Dependencies When Using Local Handler HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastapi-events.