Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Connections are attempted on idle connections that have already been closed #149

Open
joel0 opened this issue Apr 7, 2022 · 2 comments
Open

Comments

@joel0
Copy link

joel0 commented Apr 7, 2022

I'm attempting to query memcache on localhost every 10 minutes. The first Get("key") works fine, but the one 10 minutes later results in an error. The cycle repeats, so every other query succeeds. tcpdump shows that the memcache server attempted to close the TCP connection after about 30 seconds.

The errors I get are either of the following.

panic: write tcp 127.0.0.1:13590->127.0.0.1:11211: write: broken pipe
EOF

I've found I can work around this problem by calling Ping() and ignoring the returned error immediately before any Get() call.

I've boiled down a minimal repro of the problem I'm facing.

package main

import (
        "github.com/bradfitz/gomemcache/memcache"
        "fmt"
        "time"
)

func query(mc *memcache.Client) {
        // This Ping() call mitigates the problem
        // err := mc.Ping()
        // fmt.Printf("Ping(): %v\n", err)

        r, err := mc.Get("key")
        if err != nil {
                panic(err)
        }
        fmt.Printf("%v\n", string(r.Value))
}

func main() {
        mc := memcache.New("127.0.0.1:11211")

        query(mc)

        fmt.Printf("Sleeping...\n")
        time.Sleep(35 * time.Second)

        // This second query call results in an error from mc.Get("key")
        query(mc)
}
@pioz
Copy link

pioz commented Apr 29, 2022

I've tried your main and the Get works fine also after 35 seconds. I'm using a MacBook M1 with Go1.18 and Memcached v1.6.15 installed with brew install memcached without touching any config file.

@joel0
Copy link
Author

joel0 commented Apr 29, 2022

I later discovered that the memcache server I am connecting to is built inhouse. I think the difference is that Memcached is leaving idle connections open, but the memcache server I'm using closes the TCP connection after 30 second of idle.

Since I see no Memcached config parameter for idle connection timeout, I'm not sure how to provide a case you can reproduce this issue yourself.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants