golang 中的默认 HTTP 拨号超时值



我正在运行一个golang http客户端来对服务器进行压力测试。有时我收到错误"拨号 tcp 161.170.xx.xxx:80:操作超时"错误。

我认为这是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 设置超时。

默认的OSX超时可以(我认为)用sysctl net.inet.tcp检查。

最新更新