From 88f81343b0ac60b168f5248d36a1333890845b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aitor=20P=C3=A9rez=20Cedres?= Date: Mon, 31 Jul 2023 15:47:54 +0100 Subject: [PATCH] Fix heartbeat double reading MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Heartbeat frame is just a header frame. We were reading the header once, and then reading 4 bytes again, during the handle of the hearbeat frame. That was missaligning the buffer and causing a panic on next iteration. Signed-off-by: Aitor Pérez Cedres --- pkg/raw/client.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pkg/raw/client.go b/pkg/raw/client.go index 3725034b..bc404a4a 100644 --- a/pkg/raw/client.go +++ b/pkg/raw/client.go @@ -387,14 +387,9 @@ func (tc *Client) handleIncoming(ctx context.Context) error { "stream", metadataUpdate.Stream()) } case internal.CommandHeartbeat: - hb := new(internal.Heartbeat) - err = hb.Read(buffer) - if err != nil { - log.Error("error decoding heartbeat body", slog.Any("error", err)) - // we can't send a notification at this point - // TODO: revisit this. What to do here? - continue - } + // We do not need to read from the buffer here because heartbeat is only a header, + // and we read the header already + hb := internal.NewHeartbeat() if tc.heartbeatCh == nil { log.Info("heartbeat channel is not registered. Use Client.NotifyHeartbeat() to receive heartbeats") continue