Golang中的默认HTTP拨号超时值是多少?

7
我正在运行一个golang的HTTP客户端来对服务器进行压力测试。有时会出现“dial tcp 161.170.xx.xxx:80: operation timed out”错误。
我认为这是HTTP客户端超时引起的。根据https://dev59.com/dWQn5IYBdhLWcg3wW2H3#16895878,我考虑增加超时值,但首先我想找出golang中默认的超时值是多少。如果它取决于操作系统而不是语言,我该如何在Mac OS中检查此值?
1个回答

10

根据 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超时时间。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接