|
|
@@ -16,9 +16,9 @@ func (w *WebsocketSafeReadWriter) WriteJSONWithChannel(v interface{}, errorChan
|
|
|
err := w.conn.WriteJSON(v)
|
|
|
|
|
|
if err != nil {
|
|
|
- // we ignore broken pipe errors and connection reset errors, but we want to
|
|
|
- // send a message to the error channel to ensure closure
|
|
|
- if !errors.Is(err, syscall.EPIPE) && !errors.Is(err, syscall.ECONNRESET) {
|
|
|
+ if errOr(err, websocket.ErrCloseSent, syscall.EPIPE, syscall.ECONNRESET) {
|
|
|
+ // if close has been sent, or error is broken pipe error or connection reset, we want to
|
|
|
+ // send a message to the error channel to ensure closure but we ignore the error
|
|
|
errorChan <- nil
|
|
|
} else if err != nil {
|
|
|
errorChan <- err
|
|
|
@@ -26,6 +26,16 @@ func (w *WebsocketSafeReadWriter) WriteJSONWithChannel(v interface{}, errorChan
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func errOr(err error, candidates ...error) bool {
|
|
|
+ res := false
|
|
|
+
|
|
|
+ for _, cErr := range candidates {
|
|
|
+ res = res || errors.Is(err, cErr)
|
|
|
+ }
|
|
|
+
|
|
|
+ return res
|
|
|
+}
|
|
|
+
|
|
|
func (w *WebsocketSafeReadWriter) Write(data []byte) (int, error) {
|
|
|
err := w.conn.WriteMessage(websocket.TextMessage, data)
|
|
|
|