tarantool / mqtt

Tarantool MQTT client
tarantool.org
BSD 2-Clause "Simplified" License
39 stars 10 forks source link

Publish always returns true (even if the server is unreachable) #11

Closed vvzvlad closed 6 years ago

vvzvlad commented 6 years ago

Суть: если выполнить mqtt_object:publish при недостижимом сервере (например, остановленном или отключенным от сети), первые несколько минут он все равно вернет true. В аналогичном случае mosquitto_pub некоторое время висит, а потом говорит "Error: Operation timed out"

Как воспроизвести:

local mqtt = require 'mqtt'
mqtt.wb = mqtt.new("id", true)
mqtt.wb:connect({host="host",port=1883,keepalive=60,log_mask=mqtt.LOG_ALL})
--отключаем/останавливаем mqtt-сервер--
local status = mqtt.wb:publish("/topic", "value", mqtt.QOS_1, mqtt.NON_RETAIN)
print(status) --Возвращает "true"
kostja commented 6 years ago

Hi, thank you for your bug report. Care to send us a pull request?

cyanide-burnout commented 6 years ago

The same issue is here. This doesn't work as expected: local status = connection:publish(topic, data, mqtt.QOS_1, mqtt.NON_RETAIN) if not status and not connection.connect then connection:reconnect() end

vvzvlad commented 6 years ago

@kostja I do not know how to fix this, so I can not do pull request

alg1973 commented 6 years ago

assigned to @romankhabibov

dedok commented 6 years ago

@vvzvlad @cyanide-burnout can't reproduce. Can you say OS?

dedok commented 6 years ago

@vvzvlad can you retest this with the latest master?

Thanks!

cyanide-burnout commented 6 years ago

Debian 8 x64

vvzvlad commented 6 years ago

OS: Darwin MBP.local 17.5.0 Darwin Kernel Version 17.5.0: Fri Apr 13 19:32:32 PDT 2018; root:xnu-4570.51.2~1/RELEASE_X86_64 x86_64

Found new bug:

send status:    true    5
send status:    true    6
send status:    true    7
send status:    true    8
MQTT disconnect  ///Stop broker
send status:    false   The client is not currently connected.
send status:    false   The client is not currently connected.
...
send status:    false   The client is not currently connected.
send status:    false   The client is not currently connected.
send status:    true    29 ///Fake true 
send status:    true    30
send status:    true    31
....
send status:    true    39
MQTT connect   ///Real start broker
send status:    true    40
send status:    true    41

Test code:

#!/usr/bin/env tarantool
local mqtt = require 'mqtt'
local fiber = require 'fiber'

local function mqtt_disconnect_callback()
   print("MQTT disconnect")
end
local function mqtt_connect_callback()
   print("MQTT connect")
end

mqtt.wb = mqtt.new("test_id", true)
print(mqtt.wb:connect({}))
mqtt.wb:on_disconnect(mqtt_disconnect_callback)
mqtt.wb:on_connect(mqtt_connect_callback)

local function test()
   while true do
      print("send status:", mqtt.wb:publish("/topic", "", mqtt.QOS_1, mqtt.NON_RETAIN))
      fiber.sleep(1)
   end
end
fiber.create(test)
dedok commented 6 years ago

This is an libmosquito issue, and also this behaviour definitely changed after fixes/patches.

So I close this, I guess, that we have to create a new issue, if this will be repeated.