So I’m kinda paranoid about stuff like this. I’m using the Gin framework and Gorilla WebSocket for the connection. My question is — is websocket.Conn.Close() enough to fully close the client connection, or do I also need to call gin.Context.Abort() after closing the WebSocket? Here’s some sample code to show what I mean.
func HandleWebSocket(c *gin.Context) {
conn, err := upgrader.Upgrade(c.Writer, c.Request, nil)
if err != nil {
fmt.Printf("Failed to upgrade connection: %v\n", err)
return
}
defer conn.Close()
fmt.Println("WebSocket connection established.")
for {
messageType, message, err := conn.ReadMessage()
if err != nil {
// Are those conn.Close() enough to close client connection completely.
conn.Close()
}
fmt.Printf("Received: %s\n", message)
if err := conn.WriteMessage(messageType, message); err != nil {
conn.Close()
}
if string(message) == "close" {
conn.Close()
}
}
fmt.Println("WebSocket connection closed.")
}
Is conn.Close() enough to fully close the client connection, or do I need to call c.Abort() separately?