Version 0.30.4 cause tarlette.requests.ClientDisconnect exception in await request.body()
in FastAPI framework
#2406
-
Using 0.30.4 uvicorn with FastAPI app cause ConnectionClosed error: I have the route that acts as a proxy for legacy service: import httpx
legacy_backend_client = httpx.AsyncClient()
legacy_proxy = APIRouter(include_in_schema=False)
@legacy_proxy.route(
'/{full_path:path}',
methods=[
'GET',
'PATCH',
'POST',
'PUT',
'DELETE',
'OPTIONS',
],
include_in_schema=False,
)
async def proxy_for_legacy(request: Request):
# Prepare headers (add additional if needed)
headers = request.headers.mutablecopy()
headers.setdefault(HTTP_CORRELATION_ID_HEADER, request.state.correlation_id)
logger.debug('request proxied URL: %s', request.url.path)
...
# Step 2. Request the legacy backend
legacy_backend_url = urljoin(LEGACY_BASE_ADDR, request.url.path)
logger.info('legacy path [%s]: %s', request.method, legacy_backend_url)
try:
request_body = await request.body() <-- stop working
except starlette.requests.ClientDisconnect:
return JSONResponse(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
content={'message': 'NSomething wrong'},
) After updating to 0.30.4, this code stopped working due to a permanent CloentDisconnect exception. |
Beta Was this translation helpful? Give feedback.
Answered by
Kludex
Aug 2, 2024
Replies: 1 comment
-
This should be fixed in 0.30.5. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kludex
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should be fixed in 0.30.5.