Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions daemon/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ func (p *SocketHandler) handleConnection(conn net.Conn) {
// Only process heartbeat if codeTracking is enabled
if p.config.CodeTracking == nil || p.config.CodeTracking.Enabled == nil || !*p.config.CodeTracking.Enabled {
slog.Debug("Heartbeat message received but codeTracking is disabled, ignoring")
encoder := json.NewEncoder(conn)
encoder.Encode(map[string]string{"status": "disabled"})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error returned by encoder.Encode is not handled. This could lead to silent failures if writing the response to the connection fails. It's important to check for errors and log them to ensure robust operation, similar to how it's handled in the handleStatus function.

if err := encoder.Encode(map[string]string{"status": "disabled"}); err != nil {
				slog.Error("Error encoding 'disabled' status response", slog.Any("err", err))
			}

return
}
buf, err := json.Marshal(msg)
Expand All @@ -140,6 +142,10 @@ func (p *SocketHandler) handleConnection(conn net.Conn) {
if err := p.channel.Publish(PubSubTopic, chMsg); err != nil {
slog.Error("Error publishing heartbeat topic", slog.Any("err", err))
}

// Send acknowledgment to client
encoder := json.NewEncoder(conn)
encoder.Encode(map[string]string{"status": "ok"})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the other change, the error from encoder.Encode is not handled here. Please add error checking and logging to prevent silent failures when sending the acknowledgment.

if err := encoder.Encode(map[string]string{"status": "ok"}); err != nil {
			slog.Error("Error encoding 'ok' status response", slog.Any("err", err))
		}

default:
slog.Error("Unknown message type:", slog.String("messageType", string(msg.Type)))
}
Expand Down