Module: check_mk
Branch: master
Commit: 3751c300ea1c8c47d5a7a58fa69d503c7655686f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3751c300ea1c8c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri May 18 19:35:17 2018 +0200
6105 FIX CMC check helper: Fixed issues related to check includes not being loaded
When using the Check_MK Microcore several random checks could not be executed
because the helper were not loading the check includes in all cases. This was
some kind of race condition which could happen during check helper initialization.
This regression was introduced with 1.5.0b3.
Change-Id: I1d8222740ced014be938265e798ed20f5d150745
---
.werks/6105 | 15 +++++++++++++++
cmk_base/checks.py | 16 +++++++++++++---
2 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/.werks/6105 b/.werks/6105
new file mode 100644
index 0000000..36fd5a4
--- /dev/null
+++ b/.werks/6105
@@ -0,0 +1,15 @@
+Title: CMC check helper: Fixed issues related to check includes not being loaded
+Level: 2
+Component: core
+Class: fix
+Compatible: compat
+Edition: cee
+State: unknown
+Version: 1.6.0i1
+Date: 1526664697
+
+When using the Check_MK Microcore several random checks could not be executed
+because the helper were not loading the check includes in all cases. This was
+some kind of race condition which could happen during check helper initialization.
+
+This regression was introduced with 1.5.0b3.
diff --git a/cmk_base/checks.py b/cmk_base/checks.py
index 6316ffc..288483a 100644
--- a/cmk_base/checks.py
+++ b/cmk_base/checks.py
@@ -306,18 +306,28 @@ def _get_cached_check_includes(check_file_path, cache_file_path):
if check_stat.st_mtime >= cache_stat.st_mtime:
raise OSError("Cache is too old")
- if cache_stat.st_size == 0:
+ # There are no includes (just the newline at the end)
+ if cache_stat.st_size == 1:
return [] # No includes
+ # store.save_file() creates file empty for locking (in case it does not exists).
+ # Skip loading the file.
+ # Note: When raising here this process will also write the file. This means it
+ # will write it another time after it was written by the other process. This
+ # could be optimized. Since the whole caching here is a temporary(tm) soltion,
+ # we leave it as it is.
+ if cache_stat.st_size == 0:
+ raise OSError("Cache generation in progress (file is locked)")
+
x = open(cache_file_path).read().strip()
if not x:
- return []
+ return [] # Shouldn't happen. Empty files are handled above
return x.split("|")
def _write_check_include_cache(cache_file_path, includes):
store.makedirs(os.path.dirname(cache_file_path))
- store.save_file(cache_file_path, "|".join(includes))
+ store.save_file(cache_file_path, "%s\n" % "|".join(includes))
def _include_cache_file_path(path):