Skip to content
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

Data race on ping #134

Closed
juanenriqueescobar opened this issue Aug 16, 2017 · 1 comment
Closed

Data race on ping #134

juanenriqueescobar opened this issue Aug 16, 2017 · 1 comment

Comments

@juanenriqueescobar
Copy link

juanenriqueescobar commented Aug 16, 2017

mqtt server: https://github.com/mcollina/mosca
go version: go1.8.3 linux/amd64

go run -race *.go

// -- options:
opts := MQTT.NewClientOptions()
opts.AddBroker(address)
opts.SetClientID("receiver-golang")
opts.SetUsername("receiver")
opts.SetPassword("receiver")
opts.SetCleanSession(true)
opts.SetOrderMatters(false)
opts.SetProtocolVersion(4)

opts.SetMaxReconnectInterval(5 * time.Second)
opts.SetAutoReconnect(true)
opts.SetConnectTimeout(2 * time.Second)
opts.SetWriteTimeout(2 * time.Second)
opts.SetConnectionLostHandler(func(client MQTT.Client, err error) {
  log.Error(err)
})

opts.SetOnConnectHandler(my.onConnect)
opts.SetDefaultPublishHandler(my.defaultPublishHandler)
client = MQTT.NewClient(opts)
for {
	token := my.client.Connect()
	if token.Wait() && token.Error() != nil {
		slog.Error(token.Error())
		time.Sleep(2 * time.Second)
	} else {
		break
	}
}
WARNING: DATA RACE
Read at 0x00c42022c300 by goroutine 21:
  github.com/eclipse/paho%2emqtt%2egolang.keepalive()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/ping.go:45 +0x3d2

Previous write at 0x00c42022c300 by goroutine 26:
  github.com/eclipse/paho%2emqtt%2egolang.outgoing()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/net.go:208 +0x860

Goroutine 21 (running) created at:
  github.com/eclipse/paho%2emqtt%2egolang.(*client).Connect.func1()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/client.go:245 +0x1446

Goroutine 26 (running) created at:
  github.com/eclipse/paho%2emqtt%2egolang.(*client).Connect.func1()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/client.go:270 +0x1079
==================
==================
WARNING: DATA RACE
Read at 0x00c42022c318 by goroutine 21:
  github.com/eclipse/paho%2emqtt%2egolang.keepalive()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/ping.go:45 +0xaf4

Previous write at 0x00c42022c318 by goroutine 27:
  github.com/eclipse/paho%2emqtt%2egolang.incoming()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/net.go:128 +0x53b

Goroutine 21 (running) created at:
  github.com/eclipse/paho%2emqtt%2egolang.(*client).Connect.func1()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/client.go:245 +0x1446

Goroutine 27 (running) created at:
  github.com/eclipse/paho%2emqtt%2egolang.(*client).Connect.func1()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/client.go:271 +0x109e
==================

==================
WARNING: DATA RACE
Write at 0x00c42022c330 by goroutine 25:
  github.com/eclipse/paho%2emqtt%2egolang.alllogic()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/net.go:231 +0x843

Previous read at 0x00c42022c330 by goroutine 21:
  github.com/eclipse/paho%2emqtt%2egolang.keepalive()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/ping.go:57 +0x4c1

Goroutine 25 (running) created at:
  github.com/eclipse/paho%2emqtt%2egolang.(*client).Connect.func1()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/client.go:269 +0x1054

Goroutine 21 (running) created at:
  github.com/eclipse/paho%2emqtt%2egolang.(*client).Connect.func1()
      /home/juan/importante/proyectos/monorepo/go/src/github.com/eclipse/paho.mqtt.golang/client.go:245 +0x1446
@alsm
Copy link
Contributor

alsm commented Aug 17, 2017

Thanks, I was aware that there would be data races but naively accepted that it would be ok as I knew the timings would still work out, but it doesn't look good so the latest commit has moved to using atomics instead.

@alsm alsm closed this as completed Aug 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants