From 207cf08e880dd4b85450db40a3d3c8f614bc2da1 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Thu, 21 Jul 2016 16:47:54 +0300 Subject: [PATCH] Fix. Properly stop (e.g. remove pid file) event consumer loop in case of error. (#1766) --- .../scripts/resources/functions/event_consumer.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/resources/install/scripts/resources/functions/event_consumer.lua b/resources/install/scripts/resources/functions/event_consumer.lua index dd4de925ec..b09b24b5bb 100644 --- a/resources/install/scripts/resources/functions/event_consumer.lua +++ b/resources/install/scripts/resources/functions/event_consumer.lua @@ -501,7 +501,7 @@ function EventConsumer:bind(event_name, cb) end end -function EventConsumer:run() +function EventConsumer:_run() self._running = true -- set some huge default interval @@ -540,6 +540,18 @@ function EventConsumer:run() self._running = false end +function EventConsumer:run() + local ok, err = xpcall(function() + self:_run() + end, debug.traceback) + + if not ok then + -- ensure we stop loop and remove pid file + self:stop() + error(err) + end +end + function EventConsumer:stop() self._running = false if self._pid_file and self:_check_pid_file() then