user568109
user568109

Reputation: 48003

Timer overhead causing memory overflow

From the timer.Stop() documentation

Stop prevents the Timer from firing. It returns true if the call stops the timer, false if the timer has already expired or been stopped. Stop does not close the channel, to prevent a read from the channel succeeding incorrectly.

I need to find a way to destroy timer object or channel created in program via After or NewTimer. I am not using these functions directly, just another library that implements timeout using these. The more requests I handle the program's memory keeps on increasing and then gets killed.

I have looked into the following places but without much help:

  1. https://groups.google.com/forum/#!topic/golang-nuts/A597Btr_0P8
  2. https://groups.google.com/forum/#!topic/golang-nuts/-xnFsH_ZRqU
  3. https://groups.google.com/forum/#!topic/golang-nuts/rYthykbCLHk
  4. https://groups.google.com/forum/#!topic/golang-nuts/hjioKxSJ3Tc

Please help, need to fix this desperately.

UPDATE

The suspected code is at https://github.com/gocql/gocql/blob/986e33a705412161497203d55d0669d04282f5ff/conn.go#L546

var timeoutCh <-chan time.Time
if c.timeout > 0 {
    timeoutCh = time.After(c.timeout)
}

select {
case err := <-call.resp:
    if err != nil {
        if !c.Closed() {
            // if the connection is closed then we cant release the stream,
            // this is because the request is still outstanding and we have
            // been handed another error from another stream which caused the
            // connection to close.
            c.releaseStream(stream)
        }
        return nil, err
    }
case <-timeoutCh:
    close(call.timeout)
    c.handleTimeout()
    return nil, ErrTimeoutNoResponse
case <-c.quit:
    return nil, ErrConnectionClosed
}

How do I know this ? I ran go tool pprof to capture memprof and what it showed is :

section of memprof

Upvotes: 1

Views: 505

Answers (1)

FEiN
FEiN

Reputation: 75

I've merged a fix for this, https://github.com/gocql/gocql/pull/661 please raise an issue if you run into further issues

Upvotes: 2

Related Questions