Catch panic in sv.dispatcher() and restart
This commit is contained in:
parent
fd24369eaf
commit
e186d94f42
|
@ -53,14 +53,14 @@ func NewRemoteClient(sv *Server, conn net.Conn) *RemoteClient {
|
|||
cl.password = ""
|
||||
cl.modes = ""
|
||||
|
||||
cl.receive = make(chan *irc.Message)
|
||||
cl.receive = make(chan *irc.Message, 1024)
|
||||
cl.registered = make(chan bool)
|
||||
|
||||
cl.isRegistered = false
|
||||
cl.isAuthed = false
|
||||
cl.isClosed = false
|
||||
cl.conn = conn
|
||||
cl.writeq = make(chan string, 256)
|
||||
cl.writeq = make(chan string, 1024)
|
||||
|
||||
go cl.connReader()
|
||||
go cl.connWriter()
|
||||
|
|
19
server.go
19
server.go
|
@ -102,7 +102,12 @@ func (sv *Server) Run() {
|
|||
if err == nil {
|
||||
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) {
|
||||
|
@ -138,7 +143,16 @@ func (sv *Server) listen(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 {
|
||||
sv.queueLen = float64(len(sv.queue))
|
||||
select {
|
||||
|
@ -191,6 +205,7 @@ func (sv *Server) dispatcher() {
|
|||
time.Sleep(100 * time.Microsecond)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (sv *Server) loadConfig() {
|
||||
|
|
Loading…
Reference in New Issue