frigate_mqtt: unique client_id per instance (несколько subscriber'ов)
Bug: client_id format "composer-frigate-%d" использовал только now_ms(). Когда создаются 2 subscriber'а подряд (frigate + yoloworld) — оба получают один client_id за тот же мс, mosquitto kick'ает старый при connect нового → infinite reconnect loop, ни один не получает events стабильно. Fix: static _Atomic int instance_seq counter — tie-break суффикс. Format: "composer-frigate-%d-%d". Verify mosquitto logs: composer-frigate--2117451292-0 (frigate subscriber) composer-frigate--2117451292-1 (yoloworld subscriber) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+8
-1
@@ -228,8 +228,15 @@ int cfc_frigate_mqtt_create(const cfc_frigate_mqtt_config_t *cfg,
|
||||
atomic_init(&f->events_received, 0);
|
||||
atomic_init(&f->parse_errors, 0);
|
||||
|
||||
/* client_id уникальный per instance. now_ms() недостаточно — несколько
|
||||
* subscriber'ов создаются в один тик (frigate + yoloworld), получают
|
||||
* одинаковый client_id и mosquitto kick'aет old при connect нового
|
||||
* → reconnect loop. Добавляем статический counter для tie-break. */
|
||||
static _Atomic int instance_seq = 0;
|
||||
int seq = atomic_fetch_add(&instance_seq, 1);
|
||||
char client_id[64];
|
||||
snprintf(client_id, sizeof(client_id), "composer-frigate-%d", (int)now_ms());
|
||||
snprintf(client_id, sizeof(client_id), "composer-frigate-%d-%d",
|
||||
(int)now_ms(), seq);
|
||||
f->mosq = mosquitto_new(client_id, true, f);
|
||||
if (!f->mosq) goto fail;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user