-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
Write error on HTTP/2: "AssertionError: assert waiter is None or waiter.cancelled()" #551
Comments
Hi @PrimozGodec, I cannot reproduce this issue with a stripped down version of your code. import asyncio
from pathlib import Path
import httpx
async def send_requests(path: Path) -> list:
requests = []
async with httpx.Client(
timeout=httpx.TimeoutConfig(timeout=60), base_url="http://localhost:5000/"
) as client:
for _ in range(1000):
requests.append(_send_to_server(client, path))
results = await asyncio.gather(*requests)
return results
async def _send_to_server(client: httpx.Client, path: Path) -> httpx.Response:
# this should probably be done elsewhere
with open(path, "rb") as fd:
payload = fd.read()
size = len(payload)
headers = {"Content-Type": "application/octet-stream", "Content-Length": str(size)}
response = await client.post("/", headers=headers, data=payload)
print(response.json())
return response
if __name__ == "__main__":
path = Path(__file__).parent / 'image.pkl.zip'
asyncio.run(send_requests(path)) Hitting a very simple Quart server.from quart import Quart, request
app = Quart(__name__)
@app.route("/", methods=["POST"])
async def post() -> dict:
data = await request.get_data()
return {"size": len(data)}
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000) I'm using the same Maybe you could try again using the |
For housekeeping I'll close this, pending confirmation. |
I can confirm that this issue is fixed with the master branch. Probably it is the consequence of one of the changes. |
I said it too fast. The problem was that I didn't notice that HTTPX switched to HTTP1.1 as default. :( The issue still persists. Since I had problems to set up HTTP2 local server I changed @yeraydiazdiaz example such that it communicates with our server (which is HTTP2 compatible).
I changed:
After those changes code still works correctly. The issue appears when I add my custom waiting strategy:
This functionality makes sure that the client never sends more than 100 requests to the server. I know that it is not necessary for HTTPX but I need that functionality to prevent the client from loading too many images in the memory at once. The loading functionality is omitted here since it is not required to reproduce the error. It is also possible that waiting functionality is not good. Do you have any idea how to change it or what is the problem here? The error stops appearing when I add the lock around write as it is described in the issue description. |
Expect this to have been closed in master via #612, but happy to reopen if I've made an incorrect assessment there. |
Sorry, but it is not fixed with #612 the issue still persists. The example from the above still fails with the same error as before. I can not reopen the issue since it was not closed by me. |
Since #527 is now closed I am opening a new issue. We already discussed this error in #527 but we could not find a simple test that would reproduce the issue.
Issue When I run a code appended below I get the following error.
It seems that there is a lock required around the write function:
httpx/httpx/concurrency/asyncio.py
Lines 181 to 183 in a05ba2e
same that it is done #535 for the read.
Code to reproduce the error
The pickle file required in the code snippet is here:
image.pkl.zip
The text was updated successfully, but these errors were encountered: