-
Notifications
You must be signed in to change notification settings - Fork 29
Connection hangs forever if the WebSocket server just sends a message and close #7
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed
Description
Describe the bug
Connection hangs forever if the WebSocket server just sends a message and then close.
The client waits forever for a message, missing the only message that was sent by the server.
To Reproduce
Server code
import uvicorn
from starlette.applications import Starlette
from starlette.websockets import WebSocket
from starlette.routing import WebSocketRoute
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
await websocket.send_text("FOO")
await websocket.close()
routes = [
WebSocketRoute("/ws", endpoint=websocket_endpoint),
]
app = Starlette(debug=True, routes=routes)
if __name__ == "__main__":
uvicorn.run(app)Client code
import httpx
from httpx_ws import connect_ws
def my_client():
with httpx.Client() as client:
with connect_ws("http://localhost:8000/ws", client) as ws:
text = ws.receive_text()
return text
if __name__ == "__main__":
print(my_client())Expected behavior
The client should be able to read the message and close properly.
Configuration
- Python version: 3.7+
- httpx-ws version: 0.1.0
- httpx version: 0.23.1
Additional context
- Doesn't happen if we add an
asyncio.sleepor areceive_*operation on the server side - Doesn't happen with
websocketslibrary
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinghelp wantedExtra attention is neededExtra attention is needed