]> git.ipfire.org Git - thirdparty/knot-resolver.git/commit
cache: fix race in assert_right_version obs-knot-resolver-bs4hbr/deployments/1068
authorPetr Špaček <petr.spacek@nic.cz>
Mon, 7 Sep 2020 14:08:05 +0000 (16:08 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Mon, 7 Sep 2020 15:47:47 +0000 (17:47 +0200)
commitf986f462459d567b65d2d1af91829d4b34b3c8c7
treebe7b765972bbc5ebbf74fc9337e4cb53ad1c633b
parentb65e8977566be831c0308390b70fc2151f40e4e7
cache: fix race in assert_right_version

This change fixes race condition in assert_right_version(). Racy
situation:
- Two instances have the (empty) cache open: New binary and old binary.
- New binary executes count() inside assert_right_version(), which
  internally starts RO transaction. Returned count is 0.
- Old binary does some writes (RW transaction parallel to RO in the first
  process).
- New binary skips cache clear because cache was empty at the time of check.
- Result: The old binary wrote data with an old format into cache which
  was not cleared and silenty changed version number to a new one.

This is not complete fix because we lack mechanism to detect cache format
change at run-time, but at least it removes one nasty corner case and
cost of this change seems to be minimal.
lib/cache/api.c