Skip to content

Commit

Permalink
address issues with queue error handling in autopaho, return ErrInval…
Browse files Browse the repository at this point in the history
…idArguments for invalid publish QoS in paho
  • Loading branch information
vishnureddy17 committed Jan 29, 2024
1 parent ef0065f commit d2bd3b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions autopaho/auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,20 @@ connectionLoop:
if errors.Is(err, queue.ErrEmpty) {
c.debug.Println("everything in queue transmitted")
continue queueLoop
} else if err != nil {
// if Peek() keeps returning errors, we will loop forever.
// see https://github.com/eclipse/paho.golang/issues/234
c.errors.Printf("error retrieving queue entry: %s", err)
time.Sleep(1 * time.Second)
continue
}
r, err := entry.Reader()
if err != nil {
c.errors.Printf("error retrieving reader for queue entry: %s", err)
if err := entry.Leave(); err != nil {
c.errors.Printf("error leaving queue entry: %s", err)
}
time.Sleep(1 * time.Second)
continue
}

Expand Down Expand Up @@ -607,6 +617,7 @@ connectionLoop:
if err := entry.Leave(); err != nil { // the message was not sent, so leave it in the queue
c.errors.Printf("error leaving queue entry: %s", err)
}
time.Sleep(1 * time.Second)
}

// The error might be fatal (connection will drop) or could be temporary (i.e. PacketTimeout exceeded)
Expand Down
2 changes: 1 addition & 1 deletion paho/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ func (c *Client) PublishWithOptions(ctx context.Context, p *Publish, o PublishOp
return c.publishQoS12(ctx, pb, o)
}

return nil, fmt.Errorf("QoS isn't 0, 1 or 2")
return nil, fmt.Errorf("%w: QoS isn't 0, 1 or 2", ErrInvalidArguments)
}

func (c *Client) publishQoS12(ctx context.Context, pb *packets.Publish, o PublishOptions) (*PublishResponse, error) {
Expand Down

0 comments on commit d2bd3b6

Please sign in to comment.