mirror of
https://github.com/stryan/mumble-discord-bridge.git
synced 2024-11-22 21:35:44 -05:00
close channels so that everything dies properly
This commit is contained in:
parent
77cf328955
commit
665d42fc51
19
bridge.go
19
bridge.go
@ -68,8 +68,20 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
||||
<-ticker.C
|
||||
if mumble.State() != 2 {
|
||||
log.Println("Lost mumble connection " + strconv.Itoa(int(mumble.State())))
|
||||
die <- true
|
||||
m.Close <- true
|
||||
select {
|
||||
default:
|
||||
close(die)
|
||||
case <-die:
|
||||
//die is already closed
|
||||
}
|
||||
|
||||
select {
|
||||
default:
|
||||
close(m.Close)
|
||||
case <-m.Close:
|
||||
//m.Close is already closed
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
@ -81,6 +93,9 @@ func startBridge(discord *discordgo.Session, discordGID string, discordCID strin
|
||||
log.Println("\nGot internal die request. Terminating Mumble-Bridge")
|
||||
dgv.Disconnect()
|
||||
det.Detach()
|
||||
close(die)
|
||||
close(m.Close)
|
||||
close(toMumble)
|
||||
Bridge.Connected = false
|
||||
}
|
||||
}
|
||||
|
10
discord.go
10
discord.go
@ -137,8 +137,14 @@ func discordReceivePCM(v *discordgo.VoiceConnection, die chan bool) {
|
||||
lastReady = true
|
||||
readyTimeout.Stop()
|
||||
}
|
||||
|
||||
p, ok := <-v.OpusRecv
|
||||
var ok bool
|
||||
var p *discordgo.Packet
|
||||
select {
|
||||
case p, ok = <-v.OpusRecv:
|
||||
case <-die:
|
||||
log.Println("killing discord ReceivePCM")
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
log.Println("Opus not ok")
|
||||
continue
|
||||
|
8
main.go
8
main.go
@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"syscall"
|
||||
"time"
|
||||
@ -101,6 +102,13 @@ func main() {
|
||||
userCount := make(chan int)
|
||||
go pingMumble(*mumbleAddr, strconv.Itoa(*mumblePort), userCount)
|
||||
go discordStatusUpdate(discord, userCount)
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(3 * time.Second)
|
||||
log.Println(runtime.NumGoroutine())
|
||||
//pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||||
}
|
||||
}()
|
||||
if *autoMode {
|
||||
Bridge.AutoChan = make(chan bool)
|
||||
go AutoBridge(discord)
|
||||
|
Loading…
Reference in New Issue
Block a user