From 82ffb9804d40e16a636ca18cd867d7fae10df436 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 28 May 2020 19:52:47 -0700 Subject: [PATCH] Don't lock up websocket when sending error json; ref pterodactyl/panel#2076 --- router/router_server_ws.go | 2 +- router/websocket/websocket.go | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/router/router_server_ws.go b/router/router_server_ws.go index 2917749..7fe476a 100644 --- a/router/router_server_ws.go +++ b/router/router_server_ws.go @@ -53,7 +53,7 @@ func getServerWebsocket(c *gin.Context) { } if err := handler.HandleInbound(j); err != nil { - handler.SendErrorJson(err) + handler.SendErrorJson(j, err) } } } diff --git a/router/websocket/websocket.go b/router/websocket/websocket.go index f0471c6..269eb97 100644 --- a/router/websocket/websocket.go +++ b/router/websocket/websocket.go @@ -137,10 +137,7 @@ func (h *Handler) TokenValid() error { // Sends an error back to the connected websocket instance by checking the permissions // of the token. If the user has the "receive-errors" grant we will send back the actual // error message, otherwise we just send back a standard error message. -func (h *Handler) SendErrorJson(err error) error { - h.Lock() - defer h.Unlock() - +func (h *Handler) SendErrorJson(msg Message, err error) error { j := h.GetJwt() message := "an unexpected error was encountered while handling this request" @@ -156,13 +153,14 @@ func (h *Handler) SendErrorJson(err error) error { if !server.IsSuspendedError(err) { zap.S().Errorw( "an error was encountered in the websocket process", + zap.String("event", msg.Event), zap.String("server", h.server.Uuid), zap.String("error_identifier", u.String()), zap.Error(err), ) } - return h.Connection.WriteJSON(wsm) + return h.unsafeSendJson(wsm) } // Converts an error message into a more readable representation and returns a UUID