Passing 'timeout=None' should always result in no timeout
See original GitHub issueSpun up from https://github.com/encode/httpx/issues/411
Currently, the behavior of passing None
to the timeout
parameter in the various request entrypoints is not consistent:
import httpx
url = "https://httpbin.org/delay/10"
# (1)
httpx.get(url, timeout=None) # Times out after 5s
# (2)
client = httpx.Client(timeout=None)
client.get(url) # Does not timeout, returns after 10s
# (3)
client = httpx.Client()
client.get(url, timeout=None) # Times out after 5s
We should make sure passing None
always results in the behavior (2), i.e. no timeout should be applied, as opposed to (1) and (3) where the default timeout configuration is used.
The implementation suggested in #411 is to use a sentinel object:
# models.py
UNSET = object()
# api.py
def get(..., timeout: TimeoutTypes = UNSET, ...):
...
We need to switch to using UNSET
in all relevant places. For example (though these may not end up being relevant, as I have not solved this myself):
- Functions in
httpx/api.py
. - Methods of
BaseClient
,Client
andAsyncClient
inhttpx/client.py
. - Methods of dispatchers in
httpx/dispatch/
, esp..send()
. - Possibly other places that aren’t on the top of my head at the time of writing this. 😃
Next, we need to check for that sentinel instead of None
when deciding whether to use the default timeout config.
Notable places affected by this switch are:
.send()
methods in clients and dispatchers (only use the client’s or dispatcher’sself.timeout
iftimeout
isUNSET
, instead ofNone
).- The
.connect()
,.read()
and.write()
methods on the concurrency backend classes:
Issue Analytics
- State:
- Created 4 years ago
- Comments:24 (24 by maintainers)
Top Results From Across the Web
Always use a timeout for http requests | by Abu Ashraf Masnun
By setting a timeout, we're basically saying, if the server doesn't respond within this time, I can no longer keep waiting for it...
Read more >A Complete Guide to Timeouts in Node.js - Better Stack
Assigning timeout values prevents network operations in Node.js from blocking indefinitely. This article provides extensive instruction on how to time out ...
Read more >How to disable timeout for nginx? - Server Fault
I have added both that and proxy_connect_timeout 600; to the nginx.conf file, but the timeout is still on 60 seconds. Anything else I...
Read more >setTimeout() - Web APIs - MDN Web Docs
This value can be passed to clearTimeout() to cancel the timeout. ... When you pass a method to setTimeout() , it will be...
Read more >Better timeout handling with HttpClient - Thomas Levesque
When a timeout occurs, you'd expect to get a TimeoutException , right? Well, surprise, it throws a TaskCanceledException ! So, there's no ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, I hadn’t yet dove deep enough to see the full extent of the rabbit hole… until just now. Ouch.
Seems like a very sensible suggestion, right? Not sure why it took us such a winding road to get there. 😌