1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-27 17:23:00 +00:00

wsutil: Added graceful close checking

This commit is contained in:
diamondburned 2020-10-30 13:54:26 -07:00
parent 169cf7d9a3
commit 3fdf2f076f

View file

@ -6,6 +6,7 @@ import (
"context" "context"
"io" "io"
"net/http" "net/http"
"strings"
"time" "time"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
@ -167,6 +168,12 @@ func startReadLoop(conn *websocket.Conn, eventCh chan<- Event) {
return return
} }
// Is the error an intentional close call? Go 1.16 exposes
// ErrClosing, but we have to do this for now.
if strings.HasSuffix(err.Error(), "use of closed network connection") {
return
}
// Check if the error is a normal one: // Check if the error is a normal one:
if websocket.IsCloseError(err, websocket.CloseNormalClosure) { if websocket.IsCloseError(err, websocket.CloseNormalClosure) {
return return