Memory/Goroutine leak in driver

It looks like the driver is steadily leaking goroutines and memory. The following code demonstrates this. The number of goroutines steadily increases as does the memory, simply by holding an open bucket


package main

import (
	"fmt"
	"github.com/couchbaselabs/gocb"
	"os"
	"runtime"
	"runtime/pprof"
	"time"
)

func main() {
	bucketName := "test"

	cluster, err := gocb.Connect("couchbase://localhost:8091")
	if err != nil {
		print(err.Error())
		os.Exit(1)
	}

	bucket, err := cluster.OpenBucket(bucketName, "")
	if err != nil {
		print(err.Error())
		os.Exit(1)
	}

	println("Connected to bucket %s", bucket)

	var memStats runtime.MemStats

	for {
		println("\n\n\n")
		println(fmt.Sprintf("Number of running goroutines: %d", runtime.NumGoroutine()))

		runtime.ReadMemStats(&memStats)
		println(fmt.Sprintf("Allocated memory still in use: %dk", memStats.Alloc/1024))

		println("\n\nDump >>>>>>>>>>>>>>>>>>>>>>")
		pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)

		time.Sleep(5 * time.Second)
	}

}

Running the code shows that the goroutines are accumulating here:

github.com/couchbaselabs/gocb/gocbcore.(*memdQueue).drainTillSignal+0x13c

The issues are disabled for the driver repo; is this the right channel to raise this problem?

Hey cholick,

The best place to log issues is on our bug tracker here:
https://issues.couchbase.com/browse/GOCBC

I am curious whether you have attempted to run this code with the logger enabled to see if there is any strange behaviour happening internally? You can see how to do that here:
http://docs.couchbase.com/developer/go-beta/logging.html

Cheers, Brett

I’ve created a ticket:
https://issues.couchbase.com/browse/GOCBC-43

(Formatting with code tags failed and I couldn’t seem to re-edit, so apologies).

The debug output wasn’t enlightening, but might be to someone more familiar with the driver