Fixed server crash from client malformed data

This commit is contained in:
justin 2015-08-02 08:21:16 -04:00
parent e93564e777
commit db91c5e08b

View File

@ -67,17 +67,18 @@ func (c *Client) handleIncoming() {
c.Server.AddClient(c) c.Server.AddClient(c)
for { for {
message, err := c.Decode() message, err := c.Decode()
if err != nil || message == nil { if err != nil {
_, closedError := err.(*net.OpError) _, closedError := err.(*net.OpError)
if err == io.EOF || err == io.ErrClosedPipe || closedError || strings.Contains(err.Error(), "use of closed network connection") { if err == io.EOF || err == io.ErrClosedPipe || closedError || strings.Contains(err.Error(), "use of closed network connection") {
return return
} }
println("Error decoding incoming message", err.Error())
return continue
//continue }
if message == nil || message.Len() == 0 {
continue
} }
//println(message.String())
c.idleTimer.Stop() c.idleTimer.Stop()
c.idleTimer = time.AfterFunc(time.Minute, c.idle) c.idleTimer = time.AfterFunc(time.Minute, c.idle)