Don't lock up websocket when sending error json; ref pterodactyl/panel#2076

This commit is contained in:
Dane Everitt 2020-05-28 19:52:47 -07:00
parent 54510057bb
commit 82ffb9804d
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 4 additions and 6 deletions

View File

@ -53,7 +53,7 @@ func getServerWebsocket(c *gin.Context) {
} }
if err := handler.HandleInbound(j); err != nil { if err := handler.HandleInbound(j); err != nil {
handler.SendErrorJson(err) handler.SendErrorJson(j, err)
} }
} }
} }

View File

@ -137,10 +137,7 @@ func (h *Handler) TokenValid() error {
// Sends an error back to the connected websocket instance by checking the permissions // 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 // 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. // error message, otherwise we just send back a standard error message.
func (h *Handler) SendErrorJson(err error) error { func (h *Handler) SendErrorJson(msg Message, err error) error {
h.Lock()
defer h.Unlock()
j := h.GetJwt() j := h.GetJwt()
message := "an unexpected error was encountered while handling this request" 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) { if !server.IsSuspendedError(err) {
zap.S().Errorw( zap.S().Errorw(
"an error was encountered in the websocket process", "an error was encountered in the websocket process",
zap.String("event", msg.Event),
zap.String("server", h.server.Uuid), zap.String("server", h.server.Uuid),
zap.String("error_identifier", u.String()), zap.String("error_identifier", u.String()),
zap.Error(err), 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 // Converts an error message into a more readable representation and returns a UUID