ccy
ccy

Reputation: 1415

Default HTTP dial timeout value in golang

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?

Upvotes: 7

Views: 9343

Answers (1)

Intermernet
Intermernet

Reputation: 19418

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.

Upvotes: 10

Related Questions