-
-
Notifications
You must be signed in to change notification settings - Fork 949
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
test_custom_middleware[trio] fails on 1-core-VM #1255
Comments
@bmwiedemann I am getting the same issue on an import httpx
import asyncio
from starlette.applications import Starlette
from starlette.routing import Route
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.middleware import Middleware
async def error(request):
raise RuntimeError("oops")
class MyMiddleware(BaseHTTPMiddleware):
async def dispatch(self, request, call_next):
return await call_next(request)
app = Starlette(routes=[Route("/error", error)], middleware=[Middleware(MyMiddleware)])
async def main():
async with httpx.AsyncClient(app=app) as client:
_ = await client.get("http://testserver/error")
asyncio.run(main()) $ python example.py
Traceback (most recent call last):
File "/Users/florimond/Desktop/test.py", line 26, in <module>
asyncio.run(main())
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/Users/florimond/Desktop/test.py", line 23, in main
_ = await client.get("http://testserver/error")
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/httpx/_client.py", line 1722, in get
return await self.request(
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/httpx/_client.py", line 1481, in request
response = await self.send(
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/httpx/_client.py", line 1568, in send
response = await self._send_handling_auth(
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/httpx/_client.py", line 1604, in _send_handling_auth
response = await self._send_handling_redirects(
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/httpx/_client.py", line 1640, in _send_handling_redirects
response = await self._send_single_request(request, timeout)
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/httpx/_client.py", line 1681, in _send_single_request
) = await transport.handle_async_request(
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/httpx/_transports/asgi.py", line 157, in handle_async_request
await self.app(scope, receive, send)
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__
await self.middleware_stack(scope, receive, send)
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/middleware/errors.py", line 159, in __call__
await self.app(scope, receive, _send)
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/middleware/base.py", line 57, in __call__
task_group.cancel_scope.cancel()
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 562, in __aexit__
raise ExceptionGroup(exceptions)
anyio._backends._asyncio.ExceptionGroup: 2 exceptions were raised in the task group:
----------------------------
Traceback (most recent call last):
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/middleware/base.py", line 35, in call_next
message = await recv_stream.receive()
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/anyio/streams/memory.py", line 79, in receive
return self.receive_nowait()
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/anyio/streams/memory.py", line 72, in receive_nowait
raise EndOfStream
anyio.EndOfStream
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/middleware/base.py", line 55, in __call__
response = await self.dispatch_func(request, call_next)
File "/Users/florimond/Desktop/test.py", line 15, in dispatch
return await call_next(request)
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/middleware/base.py", line 37, in call_next
raise RuntimeError("No response returned.")
RuntimeError: No response returned.
----------------------------
Traceback (most recent call last):
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/middleware/base.py", line 30, in coro
await self.app(scope, request.receive, send_stream.send)
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in __call__
raise exc
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/exceptions.py", line 71, in __call__
await self.app(scope, receive, sender)
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/routing.py", line 656, in __call__
await route.handle(scope, receive, send)
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/routing.py", line 259, in handle
await self.app(scope, receive, send)
File "/Users/florimond/.pyenv/versions/3.9.0/lib/python3.9/site-packages/starlette/routing.py", line 61, in app
response = await func(request)
File "/Users/florimond/Desktop/test.py", line 10, in error
raise RuntimeError("oops")
RuntimeError: oops This seems to have been introduced via #1157 (cc @uSpike) which switched the behavior of detecting "response not received". Switching back to eg The expectation here would be that |
@florimondmanca this error is happening to me too, is there any solution you'd recommend if we don't want to downgrade Starlette? |
The fix will be on Starlette 0.17.0. |
@Kludex awesome, do you know when that will be? |
Yep, whenever another member approves #1324 |
The problem is still alive! please refer to above link |
Indeed, have been seeing this persistently even since an upgrade to 0.17.1:
There's no pattern I can discern after a few hours of trying to reproduce. Happens on all request routes and with both short and long request durations. This service is hosted behind an AWS ALB; I wouldn't expect client-side issues there (such as disconnections). End users are seeing 503's when this occurs, so it's not like they're disconnecting early. We're using FastAPI on top of it, with custom exception handling middleware and also other middleware. Tried to reproduce with an always-failing middleware but that sends a response correctly. The only suggestions I've seen seem to be downgrading starlette; I can give that a shot. We've been running this service for at least 2 years now; this only started occurring a couple months ago, intermittently. |
@kalzoo any success with downgrading starlette? |
This is still happening in 0.17.1 |
I could not find any other solution than to downgrade
Obviously, things are back to normal. I still can't figure out what's the root cause behind this exception |
The original issue here was solved. Please create a discussion with a showcase of when the new potential issue happens. I'll lock this, so we can have things in the right place, and we don't mislead future users checking this issue. Messages here will not make any difference as, again, the original issue was solved. |
Checklist
master
.Describe the bug
While working on reproducible builds for openSUSE, I found that our
python-starlette-0.16.0
package failed 1 test when running in a 1-core-VM (usually this happens due to differences in scheduling/timing)To reproduce
maybe run tests as
taskset 1 pytest
or on Debian or openSUSE run
Expected behavior
tests should pass
Actual behavior
test_custom_middleware[trio]
failsDebugging material
Environment
Additional context
This bug was found while working on reproducible builds for openSUSE.
The text was updated successfully, but these errors were encountered: