mgo

mgo.Dial creates multiple pingers without a valid connection

Bug #1342547 reported by Dave Cheney on 2014-07-16
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mgo
Undecided
Unassigned

Bug Description

Dialing a non existent server creates several pingers which persist for several seconds even if there is no valid connection.

lucky(~/src) % cat mg.go
package main

import (
        "bytes"
        "log"
        "runtime"
        "time"

        "labix.org/v2/mgo"
)

func main() {
        go func() {
                log.Print("Dialing ... ")
                _, err := mgo.Dial("127.0.0.1:1234")
                if err != nil {
                        log.Println("Dial failed:", err)
                }
        }()

        for {
                buf := make([]byte, 1<<14)
                n := runtime.Stack(buf, true)
                buf = buf[:n]
                log.Printf("There are %d pingers active\n", bytes.Count(buf, []byte("labix.org/v2/mgo.(*mongoServer).pinger")))
                time.Sleep(2 * time.Second)
        }
}

lucky(~/src) % go run mg.go
2014/07/16 16:32:48 There are 0 pingers active
2014/07/16 16:32:48 Dialing ...
2014/07/16 16:32:50 There are 2 pingers active
2014/07/16 16:32:52 There are 3 pingers active
2014/07/16 16:32:54 There are 3 pingers active
2014/07/16 16:32:56 There are 4 pingers active
2014/07/16 16:32:58 There are 3 pingers active
2014/07/16 16:32:59 Dial failed: no reachable servers
2014/07/16 16:33:00 There are 3 pingers active
2014/07/16 16:33:02 There are 2 pingers active
2014/07/16 16:33:04 There are 0 pingers active
2014/07/16 16:33:06 There are 0 pingers active

This might be why there are so many pingers running in the background in our Juju tests.

Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Yes, pingers sleep for a few seconds and only die once they are going to try again and perceive that the socket has been closed.

We may unify all pingers into a single one in the future, but the sole existence of a goroutine isn't really a bug.

Changed in mgo:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers