From 703e2622bd398839f9e548674b523be53aac0d35 Mon Sep 17 00:00:00 2001 From: Michal Kuratczyk Date: Mon, 2 Dec 2024 09:24:16 +0100 Subject: [PATCH] check err --- pkg/mqtt_client/consumer_v5.go | 6 +++++- pkg/mqtt_client/publisher_v5.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/mqtt_client/consumer_v5.go b/pkg/mqtt_client/consumer_v5.go index eae6a08..0280734 100644 --- a/pkg/mqtt_client/consumer_v5.go +++ b/pkg/mqtt_client/consumer_v5.go @@ -91,7 +91,11 @@ func (c Mqtt5Consumer) Start(ctx context.Context, subscribed chan bool) { if err != nil { log.Error("consumer connection failed", "id", c.Id, "error", err) } - c.Connection.AwaitConnection(ctx) + err = c.Connection.AwaitConnection(ctx) + if err != nil { + // AwaitConnection only returns an error if the context is cancelled + return + } close(subscribed) // TODO: currently we can consume more than ConsumerCount messages diff --git a/pkg/mqtt_client/publisher_v5.go b/pkg/mqtt_client/publisher_v5.go index 2600ca3..194c671 100644 --- a/pkg/mqtt_client/publisher_v5.go +++ b/pkg/mqtt_client/publisher_v5.go @@ -68,7 +68,11 @@ func (p *Mqtt5Publisher) Connect(ctx context.Context) { if err != nil { log.Error("publisher connection failed", "id", p.Id, "error", err) } - connection.AwaitConnection(ctx) + err = connection.AwaitConnection(ctx) + if err != nil { + // AwaitConnection only returns an error if the context is cancelled + return + } p.Connection = connection }