When it comes to timing out HTTP requests, it looks like node.js has three separate timeouts:
Can anyone clarify what the difference is between each of these methods and why someone would want to use each one?
req.setTimeout
and res.setTimeout
ultimately result in the same underlying system call that sets the timeout on the TCP socket itself using the corresponding libuv/os calls. So I think both are equivalent and you can you whichever one is more convenient or whichever one feels semantically clearer to you. I could be wrong about this though so if anyone else knows for certainly feel free to correct me.Generally the defaults are reasonable. However, you might want to set these longer if you knew you had a lot of clients on very slow or flakey connections (you serve mobile phones in remote areas or satellites or whatever), and connections that were actually still viable we being closed due to timeout. You might want to set them shorter if you knew your clients were well-connected (like servers in the same datacenter), and you wanted to free up resources more aggressively.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With