douwu3763 2013-10-31 00:39
浏览 76
已采纳

Golang中的默认HTTP拨号超时值

I am running a golang http client to stress test a server. Sometimes I got error "dial tcp 161.170.xx.xxx:80: operation timed out" error.

I think this is a HTTP client timeout. I am thinking about increase the timeout value based on https://stackoverflow.com/a/16895878/198497, but I would like to find out what's the default timeout value in golang first. If it is depends on os instead of language, how can I check this value in Mac OS?

  • 写回答

1条回答 默认 最新

  • dongtuo6562 2013-10-31 01:43
    关注

    According to 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.
    

    So the default timeout, without taking into account OS imposed limits is none.

    The timeout can be set with SetDeadline.

    The default OSX timeout can (I think) be checked with sysctl net.inet.tcp.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型