Celebrating 700K+ Installs Up to 35% OFF! View Details →

[Bug 9.4.2] Slave deletes all synced websites right after each full sync + `mgt_options` sync fails

Published a month ago

# SafeLine WAF
# ❓ question
# 🐞 bug

Published a month ago

profile_photo

Aurélien

Updated a month ago

0

Setup: master and slave both on 9.4.2 -g images with identical digests (mgt sha256:812e3039…), postgres 15.18, Ubuntu, Docker 28.5. Master installed 2024-11 and upgraded 8.4.0 → 8.5.1 → 9.0.2 → 9.4.x. Slave is a fresh install with manager.sh: empty /data/safeline, licence entered in the web UI, then joined with mgt start-sync -m <master>:9443 -t <token>. No DB restore, no manual SQL. Reproduced twice.

Problem 1 (main): the slave never keeps any website.
• full_sync_table_mgt_website inserts the master's 17 sites with the master's ids
• about 10 s later the same sync task deletes them one by one
• the task still ends with status=3 (success) and an empty error
• it repeats every 2 min; after about 35 min, mgt_website showed ins=306 / del=306 / live=0

Problem 2: mgt_options full sync fails every time with a duplicate primary key, so later options (custom block pages, response_config, licence runtime options) are never synced.

Details below 👇

profile_photo

Aurélien

Updated a month ago

0

(2/4) Problem 1: evidence (log_statement=mod on the slave, every statement comes from safeline-mgt)

12:55:14.968 INSERT INTO "mgt_website" (...,"id") ... ON CONFLICT ("id") DO UPDATE ...   x17
12:55:15.076 DELETE FROM "mgt_website" WHERE NOT id IN ('19','9','16',...,'18')  -- keeps all 17, OK
12:55:25.114 DROP TABLE IF EXISTS statistics_*_<id>        -- matches stat_enabled=false
12:55:25.117 CREATE TABLE "statistics_basics_2" ...        -- site 2 has stat_enabled=true
12:55:25.155 DROP TABLE IF EXISTS mgt_security_posture_<id> -- sp_enabled=false on all sites
12:55:25.167 DELETE FROM "mgt_website" WHERE id = '7'
12:55:25.168 DELETE FROM "mgt_website" WHERE id = '2'
...          (all 17 sites deleted)

Task log (mgt_sync_task.logs): create or update row … success x17 → reload full website config success → trigger website stat enabled success x17 → trigger website sp enabled success x17 → sync event consumer success x17 → handle table task success

• On the master, SELECT count(*) FROM mgt_master_sync_event = 0, so these are not deletions replicated from the master.
• The mgt binary includes the function names model.(*Website).SyncEventConsumer and model.NewWebsiteDeleteEvent. The per-site consumer seems to turn each synced site into a delete event.

profile_photo

Aurélien

Updated a month ago

0

(3/4) Problem 2: mgt_options duplicate primary key

level=ERROR msg="failed to create or update row options{key=captcha_page}: ERROR: duplicate key value violates unique constraint \"mgt_options_pkey\" (SQLSTATE 23505)" module=sync_worker.mgt_options source=/work/rpc/worker.go:886

The slave runs:

1INSERT INTO "mgt_options" ("created_at","updated_at","key","value","id")
2VALUES (...,'captcha_page','<html>...','42')
3ON CONFLICT ("key") DO UPDATE SET created_at=..., updated_at=..., value=...

The conflict target is key, but the master's id is inserted too. A fresh slave seeds about 102 options at startup (ids 1–102), so a key that exists only on the master collides on the id (on the master, captcha_page is id 42; on the slave, id 42 is migrate_site_proxy). The task stops at the first failure (status 4).

In our case, 14 ids collide: 14, 20, 23, 25, 37, 39, 40, 41, 42, 44, 49, 69, 73, 94 (captcha_page, auth_defense_page, response_config, purchased, detector, …). Any master upgraded over several versions will have different ids than a fresh slave.

Suggested fix: don't send id for options (they're unique by key), or skip the failing row instead of aborting the whole task.

profile_photo

Aurélien

Updated a month ago

0

(4/4) Workaround for problem 2 (applied, works) and remaining issue
On the slave, move the colliding rows above the master's id range:

1BEGIN;
2UPDATE mgt_options SET id = id + 1000 WHERE (id,key) IN
3((14,'crawler_group_id'),(20,'webhook_config'),(23,'init_website_config_global'),
4(25,'init_mgt_ssl_cert'),(37,'migrationTCD_v9.0.0_01'),(39,'migration_log_Config'),
5(40,'migration_report_log_config'),(41,'migrate_global_proxy'),(42,'migrate_site_proxy'),
6(44,'migrate_global_ssl_protocols_default'),(49,'account_config'),
7(69,'customer_service_config'),(73,'migrate_policy_pattern'),(94,'migrate_acl_query_key'));
8SELECT setval('mgt_options_id_seq', 2000);
9COMMIT;

After this, mgt_options syncs fine (status 3, no errors, custom pages arrive).
⚠️ Problem 1 is still there with every option synced: the websites are still inserted and then deleted on every cycle.

Side notes:
• the master's mgt_sync_client still lists a previous slave install from the same host (removed with manager.sh, no uninstall entry in mgt_sync_log). The web UI shows only the current slave.
• master log: msg="sync event producer not found in %s" module=sync_worker.<slave>.mgt_node_key source=/work/rpc/worker.go:1623 !BADKEY=*model.NodeKey
• the master itself is fine: mgt_website there has 13 ins / 1 del in 6 weeks, 17 live

profile_photo

Carrie

Updated a month ago

0

Hi <@837677162614095883> ,

Regarding Issue 1, our team is already aware of this issue, and it will be fixed in SafeLine 9.4.3, which is expected to be released soon.

Regarding Issue 2, our engineers have successfully reproduced the issue, and we’ve submitted an internal bug report to our product team for further investigation and resolution.

As for the additional information you provided, we haven’t been able to reproduce those issues so far. If you encounter them again, please help us check the following:

  • Check whether the master and slave nodes still display each other’s information on the page shown in the attached screenshot.
  • Check whether any synchronization tasks are still present or running.
  • Confirm whether the issue can be reproduced consistently.
  • Provide the exact steps leading to the issue, including which node you unbound first and any subsequent operations.

This information would help our engineers investigate the remaining issues more effectively.

Thank you for the detailed report.
QwrZb32bIozX5Zx9ZpHcQ3GNnRf.png