Skip to content

Commit db8f3de

Browse files
committed
fix: Ensure Unsubscribe waits for operation completion using getTokenError (#421)
Signed-off-by: FelixTing <[email protected]>
1 parent cd3dadf commit db8f3de

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

Jenkinsfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//
22
// Copyright (c) 2019 Intel Corporation
3+
// Copyright (c) 2025 IOTech Ltd
34
//
45
// Licensed under the Apache License, Version 2.0 (the "License");
56
// you may not use this file except in compliance with the License.
@@ -15,5 +16,6 @@
1516
//
1617

1718
edgeXBuildGoMod (
18-
project: 'go-mod-messaging'
19+
project: 'go-mod-messaging',
20+
goVersion: '1.23'
1921
)

internal/pkg/mqtt/client.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,12 @@ func (mc *Client) Unsubscribe(topics ...string) error {
201201
defer mc.subscriptionMutex.Unlock()
202202

203203
token := mc.mqttClient.Unsubscribe(topics...)
204-
if token.Error() != nil {
205-
return token.Error()
204+
205+
optionsReader := mc.mqttClient.OptionsReader()
206+
207+
err := getTokenError(token, optionsReader.WriteTimeout(), UnsubscribeOperation, "Failed to unsubscribe")
208+
if err != nil {
209+
return err
206210
}
207211

208212
for _, topic := range topics {

internal/pkg/mqtt/errors.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/********************************************************************************
22
* Copyright 2020 Dell Inc.
3+
* Copyright (c) 2025 IOTech Ltd
34
*
45
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
56
* in compliance with the License. You may obtain a copy of the License at
@@ -20,9 +21,10 @@ import (
2021

2122
const (
2223
// Different Client operations.
23-
PublishOperation = "Publish"
24-
SubscribeOperation = "Subscribe"
25-
ConnectOperation = "Connect"
24+
PublishOperation = "Publish"
25+
SubscribeOperation = "Subscribe"
26+
ConnectOperation = "Connect"
27+
UnsubscribeOperation = "Unsubscribe"
2628
)
2729

2830
// TimeoutErr defines an error representing operations which have not completed and surpassed the allowed wait time.

0 commit comments

Comments
 (0)