Skip to content

net/http: panic: persistConn was already in LRU #18058

Closed
@zeropool

Description

@zeropool

Please do not ignore the windows system !!!!

What version of Go are you using (go version)?

go1.7.3

What operating system and processor architecture are you using (go env)?

Windows Server Standard 2007 SP2 32bit

panic: persistConn was already in LRU

goroutine 609111 [running]:
panic(0xa50dc0, 0x125a45d8)
        /opt/dev/gopkg/go/src/runtime/panic.go:500 +0x331
net/http.(*connLRU).add(0x125de5b4, 0x1267c510)
        /opt/dev/gopkg/go/src/net/http/transport.go:2147 +0x177
net/http.(*Transport).tryPutIdleConn(0x125de5a0, 0x1267c510, 0x0, 0x0)
        /opt/dev/gopkg/go/src/net/http/transport.go:678 +0x5d8
net/http.(*persistConn).readLoop.func2(0x0, 0x125f2b01)
        /opt/dev/gopkg/go/src/net/http/transport.go:1391 +0x32
net/http.(*persistConn).readLoop(0x1267c510)
        /opt/dev/gopkg/go/src/net/http/transport.go:1548 +0xce1
created by net/http.(*Transport).dialConn
        /opt/dev/gopkg/go/src/net/http/transport.go:1062 +0xda5

this is part of my code:


func DoRequest(/* som arguments */) {
        // Very high frequency call code
	var res *http.Response
	err = nil
	if r.Timeout > 0 {
		err = errors.New("timeout")
		c := make(chan *httpPeek)
		go func() {
			newRes, newErr := httpClient.Do(req)
			select {
			case c <- &httpPeek{newRes, newErr}:
			default:
				if newErr == nil && newRes != nil && newRes.Body != nil {
					// Discard and close so we can reuse it
					io.Copy(ioutil.Discard, newRes.Body)
					newRes.Body.Close()
				}
			}
			close(c)
		}()
		select {
		case <-time.After(r.Timeout):
		case v := <-c:
			if v != nil {
				res = v.res
				err = v.err
			}
		}
	} else {
		res, err = httpClient.Do(req)
	}
	if err != nil {
		return nil, err
	}
      // other code..
}
func init() {
	timeout := time.Minute
	httpClient = &http.Client{
		Transport: &http.Transport{
			MaxIdleConnsPerHost:   5,
			TLSClientConfig:       &tls.Config{InsecureSkipVerify: true},
			ResponseHeaderTimeout: timeout,
		},
		Timeout: timeout,
	}
}

It's very hard to reproduce, program running about 20 hours, then panic and exit !!

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions