Comments (8)
@Kludex I think Starlette is doing the wrong thing here as per django/asgiref#343, what do you think?
from hypercorn.
I did fix that on the last release: encode/starlette#2352. What Starlette version is being used here?
Also, kind a related, it would be cool if you can check django/asgiref#424. 🙏
EDIT: I just saw there's FastAPI on the traceback - FastAPI still doesn't support the last Starlette version.
from hypercorn.
What Starlette version is being used here?
0.27.0
from hypercorn.
Should be fixed now given enough time has passed for release updates.
from hypercorn.
@pgjones well for me this still the case with python:3.10-slim
and next requirements.txt
:
hypercorn~=0.16
asgi-correlation-id~=4.3
starlette~=0.37.0
jinja2~=3.1
like:
from asgi_correlation_id import CorrelationIdMiddleware, correlation_id
from hypercorn.middleware import ProxyFixMiddleware
from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.gzip import GZipMiddleware
proxy_hops = int(os.getenv('PROXY_HOPS', '0'))
proxy_mode = os.getenv('PROXY_MODE', 'legacy')
middleware = [
Middleware(CorrelationIdMiddleware, header_name='X-Request-ID'),
Middleware(GZipMiddleware, minimum_size=1000)
]
if proxy_hops > 0:
middleware.append(Middleware(ProxyFixMiddleware, mode=proxy_mode, trusted_hops=proxy_hops))
app = Starlette(middleware=middleware)
app.mount('/static', StaticFiles(directory = 'statics'), name = 'static')
templates = Jinja2Templates(directory = 'templates')
...
@app.exception_handler(500)
async def server_error(request, exc):
"""
Return an HTTP 500 page.
"""
template = "500.html"
context = {
'request': request,
'title': 'Server Error',
'company': company
}
headers = {
'X-Request-ID': str(correlation_id.get() or '')
}
return templates.TemplateResponse(template, context, status_code = 500, headers=headers)
Other middleware's works just fine, and if I would set PROXY_HOPS=0
issue disappears as I skip adding ProxyFixMiddleware
.
- zero proxies mean we don't need to load
ProxyFixMiddleware
from hypercorn.
This is likely a bug with the ProxyFixMiddleware
that is fixed in 0.17.0, just released.
from hypercorn.
Just rebuild with hypercorn~=0.17
and still issue is same:
[2024-05-27 20:06:27 +0000] [13] [ERROR] Error in ASGI Framework
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/hypercorn/asyncio/task_group.py", line 27, in _handle
await app(scope, receive, send, sync_spawn, call_soon)
File "/usr/local/lib/python3.10/site-packages/hypercorn/app_wrappers.py", line 34, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 123, in __call__
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 186, in __call__
raise exc
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 164, in __call__
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.10/site-packages/starlette_exporter/middleware.py", line 285, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/asgi_correlation_id/middleware.py", line 90, in __call__
await self.app(scope, receive, handle_outgoing_request)
File "/usr/local/lib/python3.10/site-packages/starlette/middleware/gzip.py", line 26, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.10/site-packages/hypercorn/middleware/proxy_fix.py", line 23, in __call__
scope = deepcopy(scope)
File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/lib/python3.10/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/local/lib/python3.10/copy.py", line 271, in _reconstruct
state = deepcopy(state, memo)
File "/usr/local/lib/python3.10/copy.py", line 146, in deepcopy
y = copier(x, memo)
File "/usr/local/lib/python3.10/copy.py", line 231, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/local/lib/python3.10/copy.py", line 172, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/usr/local/lib/python3.10/copy.py", line 272, in _reconstruct
if hasattr(y, '__setstate__'):
File "/usr/local/lib/python3.10/site-packages/starlette/datastructures.py", line 699, in __getattr__
return self._state[key]
File "/usr/local/lib/python3.10/site-packages/starlette/datastructures.py", line 699, in __getattr__
return self._state[key]
File "/usr/local/lib/python3.10/site-packages/starlette/datastructures.py", line 699, in __getattr__
return self._state[key]
[Previous line repeated 966 more times]
RecursionError: maximum recursion depth exceeded
from hypercorn.
Can you please re-open issue as it not yet solved?
from hypercorn.
Related Issues (20)
- Performance issue HOT 2
- Is Hypercorn server serving up response using HTTP/2 HOT 1
- FastAPI deployed with hypercorn in GCP Cloud Run returning 503 sporadically HOT 6
- Entire hypercorn server crashes when receiving trailing data on a websocket upgrade request HOT 1
- Occassionally with HTTP2, server does not send "End Stream" flag as True when all the data has been sent in response
- Can the ASGI application be specified in the config file?
- How do I log username in access log? HOT 1
- Getting permission Error [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions when running FastAPI in IIS
- Need clarification on trusted hops HOT 1
- Reload up to date SSL certificates without restarting server?
- pytest-cov / pytest-sugar not included in pyproject.toml
- TCP server keep-alive times out even though data is being received. HOT 2
- Can we please get a new release? HOT 1
- ProxyFixMiddleware throws exception when X-Forwarded-Host is present HOT 1
- Unexpected "shutdown without Lifespan support" error on Hypercorn 0.17.3 HOT 1
- Cannot start WSGI application using Dispatcher middleware to support both FastAPI and Flash app at the same time. HOT 1
- It seems hypercorn is not closing connections properly HOT 12
- ProxyFixMiddleware: Turns out GCP LBs and possibly AWS LBs only have one value in `x-forwarded-proto` HOT 1
- Opentelemetry Tracing + Logging Issue
- error `hypercorn --config python:hypercorn_config.config` 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 hypercorn.