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

Very long waiting period when connection is impossible #30

Open
vvzvlad opened this issue Dec 15, 2018 · 1 comment
Open

Very long waiting period when connection is impossible #30

vvzvlad opened this issue Dec 15, 2018 · 1 comment
Assignees
Labels
enhancement help wanted Extra attention is needed

Comments

@vvzvlad
Copy link
Contributor

vvzvlad commented Dec 15, 2018

If the server is not responding, but not refused connection, the library will wait a very long time.

Code:

mqtt=require('mqtt')
m=mqtt.new()
m:connect{host="mail.ru"}

The above code will wait a very long time to complete the last command.

I use a workaround to check availability:

   local conn = socket.tcp_connect(mqtt_host, mqtt_port, 2)
   if (conn ~= nil) then
      conn:close()
      mqtt_object = mqtt.new(mqtt_name, true)
      local mqtt_status, mqtt_err = mqtt_object:connect({host=mqtt_host, port=mqtt_port})
      ...
   else
      error('Connect to host '..mqtt_host..' failed')
   end

socket.tcp_connect will return nil if the port is unavailable after 2 seconds, thus anticipating a long wait.
It would be nice if the MQTT library allowed you to set a timeout after which the connection is considered unsuccessful.

@dedok dedok self-assigned this Jun 3, 2019
@dedok dedok added enhancement help wanted Extra attention is needed labels Jun 3, 2019
@dedok
Copy link
Contributor

dedok commented Jun 3, 2019

Hi,

It's good idea, thank you! It will be implemented, but I'm not sure about ETA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants