New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock waiting for token if error occurs while writing message and QoS == 0 #185

Closed
danielnelson opened this Issue Jan 18, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@danielnelson

danielnelson commented Jan 18, 2018

If func (p *PublishPacket) Write(w io.Writer) error { returns an error, call to Wait on the token returned from client.Publish will wait indefinitely. All of my testing has been with QoS == 0, but this might affect other modes.

steps

  1. Arrange for an error to be returned from func (p *PublishPacket) Write(w io.Writer) error {, this might be difficult, however there are a number of potential errors you could attempt to trigger. I just changed the source of this function to return an error for testing.

  2. Run this test program and Wait will never return:

package main

import (
	"fmt"
	"log"
	"os"

	paho "github.com/eclipse/paho.mqtt.golang"
)

func main() {
	paho.ERROR = log.New(os.Stdout, "E: ", 0)
	paho.CRITICAL = log.New(os.Stdout, "C: ", 0)
	paho.WARN = log.New(os.Stdout, "W: ", 0)
	paho.DEBUG = log.New(os.Stdout, "D: ", 0)

	opts := paho.NewClientOptions()
	opts.AddBroker("tcp://localhost:1883")
	opts.SetAutoReconnect(true)

	client := paho.NewClient(opts)
	client.Connect().Wait()

	token := client.Publish("test", byte(0), false, "test")
	token.Wait()
	if token.Error() != nil {
		fmt.Println(token.Error())
	}
}
@alsm

This comment has been minimized.

Contributor

alsm commented Feb 21, 2018

Thanks for reporting this, it should be fixed in the above commit, I've changed the code to set an error on the token and complete it if there was an error sending the packet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment