diff --git a/utils/wsutil/conn.go b/utils/wsutil/conn.go index b698915..6c216f8 100644 --- a/utils/wsutil/conn.go +++ b/utils/wsutil/conn.go @@ -182,10 +182,10 @@ func startReadLoop(conn *websocket.Conn, eventCh chan<- Event) { return } - // Check if the error is a normal one: - if websocket.IsCloseError(err, websocket.CloseNormalClosure) { - return - } + // // Check if the error is a normal one: + // if websocket.IsCloseError(err, websocket.CloseNormalClosure) { + // return + // } // Unusual error; log and exit: eventCh <- Event{nil, errors.Wrap(err, "WS error")} diff --git a/utils/wsutil/ws.go b/utils/wsutil/ws.go index 015cfe4..0115382 100644 --- a/utils/wsutil/ws.go +++ b/utils/wsutil/ws.go @@ -123,13 +123,20 @@ func (ws *Websocket) Send(b []byte) error { // SendCtx sends b over the Websocket with a deadline. It closes the internal // Websocket if the Send method errors out. func (ws *Websocket) SendCtx(ctx context.Context, b []byte) error { + WSDebug("Waiting for the send rate limiter...") + if err := ws.SendLimiter.Wait(ctx); err != nil { + WSDebug("Send rate limiter timed out.") return errors.Wrap(err, "SendLimiter failed") } + WSDebug("Send is passed the rate limiting. Waiting on mutex.") + ws.mutex.Lock() defer ws.mutex.Unlock() + WSDebug("Mutex lock acquired.") + if ws.closed { return ErrWebsocketClosed }