Skip to content

Commit

Permalink
Avoid writing errors if conn is hijacked
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Jun 22, 2023
1 parent 6b2a20e commit 926d49c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,16 @@ func errorHandler(logger logr.Logger, msg string) func(context.Context, http.Res
if !ok {
reqID = "unknown"
}
_ = json.NewEncoder(w).Encode(&errorMessage{RequestID: reqID})
logger.Error(err, "Package service error.", "reqID", reqID)

// Only write the error if the connection is not hijacked.
var ws bool
if _, err := w.Write(nil); err == http.ErrHijacked {
ws = true
} else {
_ = json.NewEncoder(w).Encode(&errorMessage{RequestID: reqID})
}

logger.Error(err, "Service error.", "reqID", reqID, "ws", ws)
}
}

Expand Down

0 comments on commit 926d49c

Please sign in to comment.