Fix broken connection close

This commit is contained in:
Jakob Borg 2015-08-20 13:58:07 +02:00
parent f76a66fc55
commit 37cbe68204

View File

@ -36,8 +36,6 @@ func sessionListener(addr string) {
} }
func sessionConnectionHandler(conn net.Conn) { func sessionConnectionHandler(conn net.Conn) {
defer conn.Close()
if err := conn.SetDeadline(time.Now().Add(messageTimeout)); err != nil { if err := conn.SetDeadline(time.Now().Add(messageTimeout)); err != nil {
if debug { if debug {
log.Println("Weird error setting deadline:", err, "on", conn.RemoteAddr()) log.Println("Weird error setting deadline:", err, "on", conn.RemoteAddr())
@ -59,6 +57,7 @@ func sessionConnectionHandler(conn net.Conn) {
if ses == nil { if ses == nil {
protocol.WriteMessage(conn, protocol.ResponseNotFound) protocol.WriteMessage(conn, protocol.ResponseNotFound)
conn.Close()
return return
} }
@ -67,6 +66,7 @@ func sessionConnectionHandler(conn net.Conn) {
log.Println("Failed to add", conn.RemoteAddr(), "to session", ses) log.Println("Failed to add", conn.RemoteAddr(), "to session", ses)
} }
protocol.WriteMessage(conn, protocol.ResponseAlreadyConnected) protocol.WriteMessage(conn, protocol.ResponseAlreadyConnected)
conn.Close()
return return
} }
@ -81,12 +81,15 @@ func sessionConnectionHandler(conn net.Conn) {
if debug { if debug {
log.Println("Weird error setting deadline:", err, "on", conn.RemoteAddr()) log.Println("Weird error setting deadline:", err, "on", conn.RemoteAddr())
} }
conn.Close()
return return
} }
default: default:
if debug { if debug {
log.Println("Unexpected message from", conn.RemoteAddr(), message) log.Println("Unexpected message from", conn.RemoteAddr(), message)
} }
protocol.WriteMessage(conn, protocol.ResponseUnexpectedMessage) protocol.WriteMessage(conn, protocol.ResponseUnexpectedMessage)
conn.Close()
} }
} }