我正在运行一个 golang http 客户端来对服务器进行压力测试。有时我会收到错误消息“dial tcp 161.170.xx.xxx:80: operation timed out”。
我认为这是 HTTP 客户端超时。我正在考虑根据 https://stackoverflow.com/a/16895878/198497 增加超时值,但我想先找出 golang 中的默认超时值是多少。如果它取决于操作系统而不是语言,我如何在 Mac OS 中检查此值?
最佳答案
根据 http://golang.org/pkg/net/#Dialer :
type Dialer struct {
// Timeout is the maximum amount of time a dial will wait for
// a connect to complete. If Deadline is also set, it may fail
// earlier.
//
// The default is no timeout.
//
// With or without a timeout, the operating system may impose
// its own earlier timeout. For instance, TCP timeouts are
// often around 3 minutes.
因此,在不考虑操作系统强加限制的情况下,默认超时为无。
可以使用 SetDeadline
设置超时.
可以(我认为)使用 sysctl net.inet.tcp
检查默认的 OSX 超时。
关于http - golang 中的默认 HTTP 拨号超时值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19696448/