layeh / gumble

gumble is a Mumble client implementation in Go (golang)
https://pkg.go.dev/mod/layeh.com/gumble
Mozilla Public License 2.0
172 stars 53 forks source link

Issues when attempting to reconnect to server #10

Closed matthieugrieger closed 9 years ago

matthieugrieger commented 9 years ago

Hi there,

So a recent feature request for MumbleDJ was to make it possible for the bot to automatically reconnect upon server connection closure or kick. I wrote this bit of code, thinking this would do the trick (the panic will not be there in the future, just there for debugging purposes):

func (dj *mumbledj) OnDisconnect(e *gumble.DisconnectEvent) {
    if e.Type == gumble.DisconnectError || e.Type == gumble.DisconnectKicked {
        fmt.Println("Disconnected from server... Will retry connection in 30 second intervals for 15 minutes.")
        reconnectSuccess := false
        for retries := 0; retries <= 30; retries++ {
            fmt.Println("Retrying connection...")
            if err := dj.client.Connect(); err == nil {
                fmt.Println("Successfully reconnected to the server!")
                reconnectSuccess = true
                break
            } else {
                panic(err)
            }
            time.Sleep(30 * time.Second)
        }
        if !reconnectSuccess {
            fmt.Println("Could not reconnect to server. Exiting...")
            dj.keepAlive <- true
            os.Exit(1)
        }
    } else {
        dj.keepAlive <- true
    }
}

However, it doesn't seem to work. Maybe I'm just approaching this wrong? This is what console spits out:

Disconnected from server... Will retry connection in 30 second intervals for 15 minutes.
Retrying connection...
panic: client is already connected

goroutine 5 [running]:
main.(*mumbledj).OnDisconnect(0xbe19a0, 0xc20805a0c0)
    /home/matthieu/programming/github/mumbledj/main.go:83 +0x473
main.*mumbledj.OnDisconnect·fm(0xc20805a0c0)
    /home/matthieu/programming/github/mumbledj/main.go:197 +0x31
github.com/layeh/gumble/gumbleutil.Listener.OnDisconnect(0xc20800ab30, 0xc20800ab40, 0xc20800ab50, 0xc20800ab60, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumbleutil/listener.go:36 +0x37
github.com/layeh/gumble/gumbleutil.(*Listener).OnDisconnect(0xc20802e0f0, 0xc20805a0c0)
    <autogenerated>:2 +0xaa
github.com/layeh/gumble/gumble.eventMultiplexer.OnDisconnect(0xc20803b020, 0xc20803b050, 0xc20805a0c0)
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumble/eventmultiplexer.go:56 +0x57
github.com/layeh/gumble/gumble.(*Client).readRoutine(0xc20805a000)
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumble/client.go:191 +0x136
created by github.com/layeh/gumble/gumble.(*Client).Connect
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumble/client.go:120 +0x63d

goroutine 1 [runnable]:
main.main()
    /home/matthieu/programming/github/mumbledj/main.go:208 +0xb7b

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/lib/go/src/runtime/asm_amd64.s:2232 +0x1

goroutine 6 [runnable]:
github.com/layeh/gumble/gumble.(*Client).pingRoutine(0xc20805a000)
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumble/client.go:163 +0x2dc
created by github.com/layeh/gumble/gumble.(*Client).Connect
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumble/client.go:121 +0x65a

It seems strange to me that the error says that there is already an existing connection when this bit of code is within the OnDisconnect() function triggered by a DisconnectEvent.

Thanks!

matthieugrieger commented 9 years ago

I just updated to the newest release of gumble and I still seem to be having the same issue:

Disconnected from server... Will retry connection in 30 second intervals for 15 minutes.
Retrying connection...
panic: client is already connected

goroutine 5 [running]:
main.(*mumbledj).OnDisconnect(0xbe19a0, 0xc2080700c0)
    /home/matthieu/programming/github/mumbledj/main.go:82 +0x47b
main.*mumbledj.OnDisconnect·fm(0xc2080700c0)
    /home/matthieu/programming/github/mumbledj/main.go:197 +0x31
github.com/layeh/gumble/gumbleutil.Listener.OnDisconnect(0xc20800ab40, 0xc20800ab50, 0xc20800ab60, 0xc20800ab70, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumbleutil/listener.go:36 +0x37
github.com/layeh/gumble/gumbleutil.(*Listener).OnDisconnect(0xc20802e0f0, 0xc2080700c0)
    <autogenerated>:2 +0xaa
github.com/layeh/gumble/gumble.eventMultiplexer.OnDisconnect(0xc20803b020, 0xc20803b050, 0xc2080700c0)
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumble/eventmultiplexer.go:56 +0x57
github.com/layeh/gumble/gumble.(*Client).readRoutine(0xc208070000)
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumble/client.go:191 +0x136
created by github.com/layeh/gumble/gumble.(*Client).Connect
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumble/client.go:120 +0x63d

goroutine 1 [chan receive]:
main.main()
    /home/matthieu/programming/github/mumbledj/main.go:208 +0xb7b

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
    /usr/lib/go/src/runtime/asm_amd64.s:2232 +0x1

goroutine 6 [runnable]:
github.com/layeh/gumble/gumble.(*Client).pingRoutine(0xc208070000)
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumble/client.go:163 +0x2dc
created by github.com/layeh/gumble/gumble.(*Client).Connect
    /home/matthieu/programming/github/mumbledj/.vendor/src/github.com/layeh/gumble/gumble/client.go:121 +0x65a
ghost commented 9 years ago

Can you double check and see if your local copy of gumble did get updated? I just tried called Client.Connect from a disconnect listener without problem.

matthieugrieger commented 9 years ago

It should be updated, but I can try again later. I attempted to update both gumble and gumble_ffmpeg twice, so I'd be surprised if they weren't actually updated. On Feb 25, 2015 12:26 PM, "Tim Cooper" notifications@github.com wrote:

Can you double check and see if your local copy of gumble did get updated? I just tried called Client.Connect from a disconnect listener without problem.

— Reply to this email directly or view it on GitHub https://github.com/layeh/gumble/issues/10#issuecomment-76048768.

matthieugrieger commented 9 years ago

Looks like there's some sort of strange issue going on with my dependency manager. I'll have to get back to you later on if the fix works or not (it probably does).

matthieugrieger commented 9 years ago

You were right, it was an issue with my local copy not being updated correctly. It works great now. :+1:

It seems that in my Goopfile for goop I have to order gumble, gumble_ffmpeg, and gumbleutil in the order oldest -> newest. Not really sure why this has to be the case, I'm going to post an issue there.

Thanks again!