Services are updated by triggerid in process_events function. DBupdate_services function is called for each trigger, in the function ids table for service_alarms record can be locked (because of adding new service_alarams). Then another history syncer tries to lock service_alarms and wait when previous history syncer will free the record. But it can not do it because we define mutex in DBupdate_services function. So first process locked ids table record and wait when mutex will be free, the next one history syncer tries to update ids table with locked mutex and can not do it because of previous locked ids table.