课程: Secure Coding in Go

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Setting timeouts

Setting timeouts

- [Instructor] The two top fallacies in distributed computing are that the network is reliable and the latency is zero. These problems might come from network errors, but also can be used by bad actors to run a denial of service attack. Imagine that I'm calling your server, sending a megabyte of data, one byte per second. It will take the HTTP handler more than 12 days to handle a single request. The context library is the way to handle timeouts and cancellations in Go. Every request has an associated context that you can pass to worker functions to limit the amount of time they have. The HTPP server has several fields such as ReadTimeout, ReadHeaderTimeout, WriterTimeout, IdleTimeout, and others to specify several timeouts for requests. When we look at these timeouts, we can visualize them like there. We are waiting for a connection and then reading the HTTPS or the TLS handshake, then reading the Headers and…

内容