CiscoTestAutomation / ncdiff

NETCONF Diff Engine
Apache License 2.0
24 stars 5 forks source link

Model download can hang if both workers get exceptions #23

Closed bobh66 closed 1 year ago

bobh66 commented 1 year ago

It is possible for the Model Downloader to hang if both of the workers encounter exceptions and leave their tasks in the queue.

In the DownloadWorker.run() method if self.downloader.download() raises an Exception, the worker will stop without marking the queued task as done. If that happens to both worker threads the process will hang.

A possible solution would be to catch the exceptions:

def run(self):
    while not self.downloader.download_queue.empty():
        try:
            module = self.downloader.download_queue.get(timeout=0.01)
        except Empty:
            pass
        else:
            try:
                self.downloader.download(module)
            except Exception as e:
                logger.exception(e)
            self.downloader.download_queue.task_done()
    logger.debug('Thread {} exits'.format(current_thread().name))

which will at least let the process finish without hanging.

yuekyang commented 1 year ago

Will fix this next week. Thank you.

yuekyang commented 1 year ago

Fixed as suggested. Thanks! https://github.com/CiscoTestAutomation/ncdiff/commit/6e263176035fe1c8c28c05b3a9bdadd9ed439751

bobh66 commented 1 year ago

Thanks @yuekyang !