Catch panic in sv.dispatcher() and restart

This commit is contained in:
Andreas Neue 2016-07-29 00:21:24 +02:00
parent fd24369eaf
commit e186d94f42
2 changed files with 19 additions and 4 deletions

View File

@ -53,14 +53,14 @@ func NewRemoteClient(sv *Server, conn net.Conn) *RemoteClient {
cl.password = "" cl.password = ""
cl.modes = "" cl.modes = ""
cl.receive = make(chan *irc.Message) cl.receive = make(chan *irc.Message, 1024)
cl.registered = make(chan bool) cl.registered = make(chan bool)
cl.isRegistered = false cl.isRegistered = false
cl.isAuthed = false cl.isAuthed = false
cl.isClosed = false cl.isClosed = false
cl.conn = conn cl.conn = conn
cl.writeq = make(chan string, 256) cl.writeq = make(chan string, 1024)
go cl.connReader() go cl.connReader()
go cl.connWriter() go cl.connWriter()

View File

@ -102,7 +102,12 @@ func (sv *Server) Run() {
if err == nil { if err == nil {
go sv.listenTls(laddr) go sv.listenTls(laddr)
} }
sv.dispatcher() for {
err = sv.dispatcher()
if err != nil {
xlog.Error("Dispatcher in panic: %s", err.Error())
}
}
} }
func (sv *Server) Dispatch(msg *irc.Message) { func (sv *Server) Dispatch(msg *irc.Message) {
@ -138,7 +143,16 @@ func (sv *Server) listen(laddr string) {
func (sv *Server) listenTls(laddr string) { func (sv *Server) listenTls(laddr string) {
} }
func (sv *Server) dispatcher() { func (sv *Server) dispatcher() (err error) {
defer func() {
if r := recover(); r != nil {
var ok bool
err, ok = r.(error)
if !ok {
err = fmt.Errorf("pkg: %v", r)
}
}
}()
for { for {
sv.queueLen = float64(len(sv.queue)) sv.queueLen = float64(len(sv.queue))
select { select {
@ -191,6 +205,7 @@ func (sv *Server) dispatcher() {
time.Sleep(100 * time.Microsecond) time.Sleep(100 * time.Microsecond)
} }
} }
return
} }
func (sv *Server) loadConfig() { func (sv *Server) loadConfig() {