bradfitz/gomemcache — pull request #16 by nickdavies (2013-11-14 04:51:37+00:00)
Title: Fix for bug that can cause leaked goroutines

The current connection code in client.dial will leak a goroutine forever if you pass a server that never responds or if the server becomes inaccessible.

If you want to see an example of this you can run:

```go
package main

import (
"runtime"
"time"
"fmt"
)

import "./memcache"

func main() {

// its important to pick a host that will drop not reject packets
m := memcache.New("example.com:1234")
for _ = range time.Tick(500 * time.Millisecond) {
fmt.Println(m.Get("foo"))
fmt.Println(runtime.NumGoroutine())
}

}
```

This will correctly identify a timeout and return the error but you will notice that NumGoroutines never decreases and memory slowly grows.

I switched dial to use the net.DialTimeout function the only downside to this is the detection of the error timeout, there were a few ways to identify the error, I thought this was the least horrible.