diff --git a/inc/lektor/queue.h b/inc/lektor/queue.h
index 6202754be9446818ee56bd5664ffb5302fa64687..0c03c075834e824ed60fd3fdc13f3df40c460c77 100644
--- a/inc/lektor/queue.h
+++ b/inc/lektor/queue.h
@@ -66,7 +66,7 @@ typedef struct {
 struct queue {
     pthread_mutex_t lock;
 
-    volatile lkt_event *contents;
+    volatile lkt_event *volatile contents;
     volatile size_t size;
     volatile size_t last;
 
@@ -75,7 +75,7 @@ struct queue {
 
 /* Initialize the queue. Can't fail if the passed argument is not NULL.
  * WARN: In case of out of memory this function will abort the process. */
-static inline int
+PRIVATE_FUNCTION int
 lkt_queue_new(struct queue *ret)
 {
     if (!ret)
@@ -95,7 +95,7 @@ lkt_queue_new(struct queue *ret)
 }
 
 /* Free the queue. Can't fail. */
-static inline void
+PRIVATE_FUNCTION void
 lkt_queue_free(struct queue *queue)
 {
     pthread_mutex_lock(&queue->lock);
@@ -104,7 +104,25 @@ lkt_queue_free(struct queue *queue)
     pthread_mutex_unlock(&queue->lock);
 }
 
-static inline void
+/* Is an event of the following type present in the queue?
+ * Returns 0 if the type is not present, 1 otherwise. */
+PRIVATE_FUNCTION bool
+lkt_queue_has_event(struct queue *queue, LKT_EVENT_TYPE type)
+{
+    bool ret = false;
+    pthread_mutex_lock(&queue->lock);
+    for (size_t i = 0; i < queue->last; ++i) {
+        if (queue->contents[i].type & type) {
+            ret = true;
+            break;
+        }
+    }
+    pthread_mutex_unlock(&queue->lock);
+    return ret;
+}
+
+/* Send an event into the queue */
+PRIVATE_FUNCTION void
 lkt_queue_send(struct queue *queue, LKT_EVENT_TYPE _type, void *_attr)
 {
     pthread_mutex_lock(&queue->lock);
@@ -133,7 +151,7 @@ end:
     pthread_mutex_unlock(&queue->lock);
 }
 
-static inline lkt_event
+PRIVATE_FUNCTION lkt_event
 lkt_queue_handle(struct queue *queue)
 {
     pthread_mutex_lock(&queue->lock);
@@ -154,7 +172,7 @@ end:
     return ret;
 }
 
-static inline void
+PRIVATE_FUNCTION void
 lkt_queue_make_available(struct queue *queue, LKT_EVENT_TYPE type)
 {
     pthread_mutex_lock(&queue->lock);
diff --git a/src/module/module_repo.c b/src/module/module_repo.c
index b432daf0ecb089f1ef772dfe5258c6a139f1187c..cf4403619de12033bdc6f824aa41b7bbb2f56691 100644
--- a/src/module/module_repo.c
+++ b/src/module/module_repo.c
@@ -486,11 +486,13 @@ ___handle_got_json(volatile sqlite3 *db, struct module_repo_internal *repo, cons
 }
 
 PRIVATE_FUNCTION void
-___handle_deleted_kara(volatile sqlite3 *db)
+___handle_deleted_kara(volatile sqlite3 *db, struct queue *queue)
 {
     size_t len, i;
     int *kara_ids;
     char filepath[PATH_MAX];
+    while (lkt_queue_has_event(queue, LKT_EVENT_TOUCH_KARA))
+        ___sleep();
     database_deleted_kara(db, &kara_ids, &len);
     for (i = 0; i < len; ++i) {
         if (!database_get_kara_path(db, kara_ids[i], filepath))
@@ -524,7 +526,7 @@ ___worker_update(void UNUSED *worker, void *___repo)
 
     if (ret != 2) {
         LOG_INFO("REPO", "No interrupt requested, don't skip delete kara operation");
-        ___handle_deleted_kara(repo->db);
+        ___handle_deleted_kara(repo->db, repo->queue);
     } else {
         LOG_WARN("REPO", "Handle json was interrupt, skip delete kara operation");
     }