-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add send_timeout, close_timeout, and send_x timeout parameter #2537
base: master
Are you sure you want to change the base?
Conversation
Add timeout keyword parameter to send_x calls on WebSocketResponse.
I tried writing a functional test for the Here is my attempt (that doesn't work): async def test_send_bytes_timeout(loop, test_client):
closed = loop.create_future()
raised = False
async def handler(request):
ws = web.WebSocketResponse(send_timeout=0.1)
await ws.prepare(request)
try:
# The send_bytes call returns immediately.
# I also tried with 1 GB of data to defeat buffering. That didn't work.
await ws.send_bytes(b'0')
# Calling drain doesn't help either.
await ws.drain()
except asyncio.TimeoutError:
nonlocal raised
raised = True
closed.set_result(1)
await ws.close()
return ws
app = web.Application()
app.router.add_get('/', handler)
client = await test_client(app)
async with client.ws_connect('/') as ws:
await closed
assert raised |
Codecov Report
@@ Coverage Diff @@
## master #2537 +/- ##
==========================================
+ Coverage 97.56% 97.56% +<.01%
==========================================
Files 40 40
Lines 8085 8088 +3
Branches 1413 1413
==========================================
+ Hits 7888 7891 +3
Misses 74 74
Partials 123 123
Continue to review full report at Codecov.
|
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.
Would you write tests for expired timeouts?
Should we use a timeout for ping
and pong
?
Pretty sure yes.
Also please add send_timeout
etc to client_ws.py
-- there is no reason to have no such functionality in client web socket as well.
self._receive_timeout = receive_timeout | ||
self._send_timeout = send_timeout | ||
self._close_timeout = timeout or close_timeout |
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.
Please deprecate timeout
.
Something like
if timeout is not None:
warnings.warn("timeout parameter is deprecated, use close_timeout instead", DeprecationWarning)
close_timeout = timeout
@@ -846,7 +846,8 @@ Response | |||
WebSocketResponse | |||
^^^^^^^^^^^^^^^^^ | |||
|
|||
.. class:: WebSocketResponse(*, timeout=10.0, receive_timeout=None, \ | |||
.. class:: WebSocketResponse(*, timeout=None, receive_timeout=None, \ | |||
send_timeout=None, close_timeout=10.0, \ |
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.
Please describe added params below.
@frederikaalund ping |
Sorry about the delay. I'll try to find time to implement the changes this week. Thanks for the detailed review. |
No problem! |
What do these changes do?
See the title and the discussion in #2310.
Are there changes in behavior for the user?
No. The old
timeout
parameter will take precedence over the newclose_timeout
parameter. The defaultclose_timeout
of 10.0 seconds is still in place.Related issue number
#2310
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bug)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.