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

Processor time continues to be used after a failing connect command #136

Closed
ghost opened this issue Jun 18, 2018 · 3 comments
Closed

Processor time continues to be used after a failing connect command #136

ghost opened this issue Jun 18, 2018 · 3 comments
Labels
bug This issue is a bug.

Comments

@ghost
Copy link

ghost commented Jun 18, 2018

I'm trying to write a small script that isn't guaranteed to have internet access on startup and can sometimes lose internet unexpectedly.

When there is no internet, the socket will fail to connect (as expected) due to name resolution not being available. A socket error is raised.
If connect is called again, the error will be raised again, but the processor utilization will increase.
This will continue to occur until the operating system denies you the ability to create threads.

e.x.

while True:
    try:
        mqttclient.connect()
        break
    except:
        sleep(10)
        continue

Things I've tried:

  • Calling disconnect after a failed connect
  • Only calling connect once. Once internet is established, publish never works
  • Deleting mqttclient and re-creating it

Connect will have to be called again, since socket lifetimes are limited to 24 hours.
Related: #39 #124

@liuszeng
Copy link
Contributor

Hi @zerasmus ,

We are aware of the issues you mentioned. Fixes are already merged in our internal dev branch and is pending to be released. Please stay tuned for future releases.

Thanks,
Liusu

@ghost
Copy link
Author

ghost commented Jun 18, 2018

FYI, I believe I've found the issue and a work-around:

def connect_async(self, keep_alive_sec, ack_callback=None):
self._logger.info("Performing async connect...")
self._logger.info("Keep-alive: %f sec" % keep_alive_sec)
self._start_workers()
self._load_callbacks()
self._load_username_password()
self._client_status.set_status(ClientStatus.CONNECT)
rc = self._internal_async_client.connect(keep_alive_sec, ack_callback)
if MQTT_ERR_SUCCESS != rc:
self._logger.error("Connect error: %d", rc)
raise connectError(rc)
return FixedEventMids.CONNACK_MID

The workers are started and then the internal connect raises the exception without stoping the workers.
A workaround without modifying the library is to stop the workers using the internal variables:

while True:
    try:
        mqttclient.connect()
        break
    except Exception as e:
        # Stop the internal worker
        mqttclient._mqtt_core._event_consumer.stop()
        sleep(10)
        continue

@liuszeng liuszeng added the bug This issue is a bug. label Jun 20, 2018
@liuszeng
Copy link
Contributor

Addressed in v1.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

1 participant