Skip to content
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 Websocket protocol timeouts after #939 #976

Merged
merged 1 commit into from
Oct 19, 2017

Conversation

ashleysommer
Copy link
Member

Update websocket protocol to accommodate changes in HTTP protocol from #939

Fixes #969

@r0fls
Copy link
Contributor

r0fls commented Oct 16, 2017

I still receive the request timeout with this branch. To test you can open the browser with the websocket.py example and wait 60 seconds (or, more intelligibly, decrease the timeout).

In the same vein, the below test also fails on this branch, which I would expect to pass:

$ git diff  master tests/test_request_timeout.py
diff --git a/tests/test_request_timeout.py b/tests/test_request_timeout.py
index a1d8a88..d226da3 100644
--- a/tests/test_request_timeout.py
+++ b/tests/test_request_timeout.py
@@ -138,6 +138,15 @@ Config.REQUEST_TIMEOUT = 2
 request_timeout_default_app = Sanic('test_request_timeout_default')
 request_no_timeout_app = Sanic('test_request_no_timeout')
 
+@request_timeout_default_app.websocket('/feed')
+async def feed(request, ws):
+    while True:
+        data = 'hello!'
+        print('Sending: ' + data)
+        await ws.send(data)
+        data = await ws.recv()
+        print('Received: ' + data)
+
 
 @request_timeout_default_app.route('/1')
 async def handler1(request):
@@ -149,6 +158,13 @@ async def handler2(request):
     return text('OK')
 
 
+def test_websocket_request_timeout():
+    client = DelayableSanicTestClient(request_timeout_default_app, None, 3)
+    request, response = client.get('/feed')
+    assert response.status == 200
+    assert response.text == 'hello!'

Copy link
Contributor

@r0fls r0fls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a unit test to this.

@ashleysommer
Copy link
Member Author

ashleysommer commented Oct 16, 2017

I still receive the request timeout with this branch.

Ok, I see that now too.

I believe this behaviour is actually correct. A request timeout is triggered when the client is taking too long to send the request to the server. In this case, the timeout is occurring before the websocket handshake is completed, so the protocol object does not yet have a websocket property, so it is treated like an ordinary HTTP request, so the timeout throws an error as expected. If the request timeout occurrs after the websocket handshake, then the protocol object does have a websocket property so the timeout is ignored as intended.

With that said, this PR still fixes #976 because ResponseTimeout and KeepAliveTimeout are always called after a websocket handshake, so those timeouts will always be ignored on a websocket connection.

Please let me know if that makes sense and is valid logic.

@r0fls r0fls merged commit 666c084 into sanic-org:master Oct 19, 2017
@seemethere seemethere modified the milestones: 0.6.1, 0.7.0 Nov 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants