-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Split RequestTimeout, ResponseTimeout, and KeepAliveTimeout into different timeouts #939
Conversation
… different timeouts, with different callbacks.
In this PR, all three timeouts now have their own group of tests. There have been no performance benchmarks done yet. |
Ok, while the tests are passing on my machine, they are not passing on Travis. |
… correct behaviour Fixed error where KeepAliveTimeout wasn't being triggered in the test suite, when using uvloop Fixed test cases when using other asyncio loops such as uvloop Fixed Flake8 linting errors
Woo! passing now :) |
@ashleysommer sorry still reviewing this. Looks great though. |
return new_conn | ||
|
||
|
||
class ReuseableSanicTestClient(SanicTestClient): |
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.
Is there any reason we need this ? can we use test_client
fixture in pytest-sanic
? https://github.com/yunstanford/pytest-sanic, it'd be better to maintain.
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.
This is here because I needed a custom version of the SanicTestClient
that could:
- Honor a keepalive header, and store the connection in the client for reuse.
- Reuse the existing TCP connection when making a subsequent request, if keepalive was set on the first request.
- Raise an error if we got a new connection, when we were expecting to reuse the old connection.
These customisations to the SanicTestClient
are very specific to this particular test (the KeepAliveTimeout test)
I haven't looked, but I don't think the test_client
fixture in pytest-sanic
has the ability to be customised in this manner.
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.
No, you can do them all, by simply passing your ReuseableTCPConnector
as param to test_client
.
https://github.com/yunstanford/pytest-sanic/blob/master/pytest_sanic/utils.py#L183
I'm going to go ahead and merge this now and we can improve it later, if needed. @yunstanford if you have time to make a PR with the pytest-sanic module that'd be nice. Thanks @ashleysommer! |
@r0fls Ok, thanks for merging. To be honest, I was expecting more discussion around this before merging, specifically about my choice of default values for the config variables, and the logic around deciding when each timeout is triggered. But I guess those things can be discussed in other PRs or Issues now. I don't know how many people are using/testing Another thing I thought of is the documentation. The docs for the |
@ashleysommer ok thanks. For the record, if a PR is not complete when created, and you think it requires feedback or more work (e.g. docs additions), then you can mark it as WIP to indicate that. |
Add documentation for new Timeout values, after #939
Fix Websocket protocol timeouts after #939
This is a big change to the server backend of Sanic, and my largest Sanic contribution by far. There will need to be some discussion around this.
While investigating what seemed like a relatively simple problem in Issue #902 it was discovered that Sanic uses a single timeout (called RequestTimeout), which is handled by the
connection_timeout()
callback, and controlled by the 'REQUEST_TIMEOUT' config option, to cover three different scenarios:In all three of these scenarios, the server generates a 408 ("RequestTimeout") error and sends a 408 response to the client. While this is correct for case (1), it is incorrect behaviour for scenarios (2) and (3).
Even more confusting is if you look in the test_receive_timeout.py Test code, the test code injects a delay into the response, causing the response to timeout, then throws, catches, and delivers a 408: Request Timeout. This is confusing and wrong.
In the case of (2) when our application takes too long to generate a response to a request, we should use a ResponseTimeout, and send a 5xx error.
In thecase of (3), when the keepalive timeout expires, we should not send an error at all, just log it and move on.
To put it another way,
This PR has some big changes.
There are now three different timeouts tracked by the sanic backend server, each with their own configurable timeout values, their own default values, their own callback handlers, and their own logical flow.
Fixes #902