Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default HTTP dial timeout value in golang

Tags:

http

go

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?

like image 532
ccy Avatar asked Oct 31 '13 00:10

ccy


People also ask

What is default HTTP request timeout?

The default value is 60 seconds. [server] intra-connection-timeout = 60. If the value of this stanza entry is set to 0 (or not set), connection timeouts between data fragments are governed instead by the client-connect-timeout stanza entry. The exception to this rule occurs for responses returned over HTTP (TCP).

What is HTTP timeout?

The HyperText Transfer Protocol (HTTP) 408 Request Timeout response status code means that the server would like to shut down this unused connection. It is sent on an idle connection by some servers, even without any previous request by the client.

How do you add timeout in Golang?

Syntax. The After function waits for d duration to finish and then it will return the current time on a channel. Consider the code shown below where we make use of the After function to register a timeout. package main import ( "fmt" "time" ) func timeConsuming() string { time.


Video Answer


1 Answers

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.

like image 137
Intermernet Avatar answered Oct 04 '22 05:10

Intermernet