-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Middleware not preserving state properly #207
Comments
also, it seems that a call to When posting on the problematic endpoint, it will successfully print a valid json once, and then will hang, this modified middleware can show this behavior: async def problem_middleware(res, req, data=None):
data = await res.get_json() # Will not hang
print(data) # Will print normally
my_random_number = await simple_database.get_data()
data = await res.get_json() # Will Hang forever
print(data)
return {"hello":"world"} |
The workaround is the get all data beforehand and pass it around middleware calls, before any asynchronous call |
this will be a tracking issue until I fix this properly. real fix is pause the readable side only of the socket when going async and not waiting the body, and resume again when reading or after the writable side ends. Also if we dont have any more body to receive we should not hang. |
When using a middleware that performs an asynchronous operation, the endpoint
/api/v1/my_resource_problem
stalls and never responds. In contrast, the endpoints/api/v1/my_resource
and/api/v1/my_resource_functional
work as expected.Steps to Reproduce
Run the following code:
Send a POST request with valid JSON data to the following endpoints:
/api/v1/my_resource
/api/v1/my_resource_functional
/api/v1/my_resource_problem
Expected Behavior
All endpoints should respond with (and print the posted data in the stdout):
Actual Behavior
/api/v1/my_resource
and/api/v1/my_resource_functional
respond correctly./api/v1/my_resource_problem
stalls and never replies.Additional Information
It appears that
await res.get_json()
enters an infinite loop when a previous middleware performs an asynchronous call, such asmy_random_number = await simple_database.get_data()
.Environment
Note: same behavior happens on
data = await res.get_data()
.Actually the problem seems to happen inside the
.get_data()
(it is called from the.get_json()
.The text was updated successfully, but these errors were encountered: