-
-
Notifications
You must be signed in to change notification settings - Fork 753
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
fix: upgrade is not websocket and dependencies are installed, should not warning #2360
Conversation
@Kludex Hey, would you look at that? |
Can you create a table of expected behavior you see? Also, while checking this... I've noticed that this is printed multiple times with httptools: WARNING: Unsupported upgrade request.
WARNING: No supported WebSocket library detected. Please use "pip install 'uvicorn[standard]'", or install 'websockets' or 'wsproto' manually.
WARNING: Unsupported upgrade request.
WARNING: No supported WebSocket library detected. Please use "pip install 'uvicorn[standard]'", or install 'websockets' or 'wsproto' manually.
WARNING: Unsupported upgrade request.
WARNING: No supported WebSocket library detected. Please use "pip install 'uvicorn[standard]'", or install 'websockets' or 'wsproto' manually. Does this also happens for you? |
I have created a table to describe the expected behavior and the actual behavior I observed:
yes, I also encountered the warnings multiple times with httptools. |
Is this PR fixing the multiple warnings? I tried it, and it didn't change that. I may have done something wrong? |
How did you test it? from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello, World!"}
if __name__ == '__main__':
import uvicorn
# uvicorn.run(app, http="h11")
uvicorn.run(app, http="httptools") import httpx
async def a():
headers = {"Connection": "upgrade", "Upgrade": "123"}
async with httpx.AsyncClient() as client:
response = await client.get('http://0.0.0.0:8000', headers=headers)
print(response.text)
import asyncio
asyncio.run(a()) |
I'll get back to you in some hours. I'm away. |
I'm using wscat. I'd like to see this working against: from starlette.applications import Starlette
from starlette.routing import WebSocketRoute
from starlette.websockets import WebSocket
async def route(websocket: WebSocket) -> None:
await websocket.accept()
await websocket.send_text("Hello, world!")
await websocket.close()
app = Starlette(routes=[WebSocketRoute("/ws", route)]) Running with |
Ah, got it. The |
|
||
def _should_upgrade(self) -> bool: | ||
upgrade = self._get_upgrade() | ||
return self._should_upgrade_to_ws(upgrade) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The biggest difference between h11 and httptools is that h11 strictly determines that upgrade is equal to websocket, whereas httptools does not, which leads to warnings when upgrade is not a websocket.
Are you saying that your PR just doesn't solve the multiple warnings on the scenario which should really warn? |
There seems to be two issues now, there should only be one warning prompt if a user receives a request to upgrade ws when they have not chosen to install a websocket dependency. When a user installs a websocket dependency and receives a request with an incorrect value in the upgrade field, multiple warnings are generated, which is incorrect because I already have the dependency installed, this PR is to fix that. |
Only one warning is generated now. And the warnings are friendly, if the dependency is installed and the upgrade is not supported, then only prompted the upgrade is not supported. If the dependency is not installed and the upgrade is not supported, then both are prompted. |
@urec56 This comment is the solution to this PR: #2360 (comment) If you can reproduce the problem, you can try installing this PR to verify that it solves the problem. pip install git+https://github.com/vvanglro/uvicorn.git The expected result is that you will only receive: |
Ok, I'll try it with this fix and reply here in a few days |
So, I tried this fix and it looks like it solved the problem. Thank you, guys |
I'll check this over the weekend. Sorry the delay. |
@Kludex Maybe there should be a timeout for the test action? jobs:
tests:
name: "Python ${{ matrix.python-version }} ${{ matrix.os }}"
runs-on: "${{ matrix.os }}"
+ timeout-minutes: 30 |
Yes. Some process is hanging. Do you want to create a PR for it? |
I'll do. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @vvanglro 🙏
In what release of uvicorn we can download this fix? |
0.30.6 |
Thank you |
Summary
When I upgraded uvicorn to standard, I found that I encountered a lot of
Unsupported upgrade request.
prompts in the logs, so I debugged locally and found that h11 and httptools handle upgrades with different logic. I think I should keep the same logic.If the upgrade field is not equal to websocket in h11, the
self._should_upgrade_to_ws()
method will not run, while httptools is different.Checklist