From bd1696ef65d6c9dcfa1c9338ce837d6ea5142c68 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Sun, 1 Nov 2020 09:44:02 -0800 Subject: [PATCH] wsutil: Added super verbose logs --- utils/wsutil/conn.go | 8 ++++---- utils/wsutil/ws.go | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) 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 }