[FIX/WIP] Fix concurrency problem with LMDB

This commit is contained in:
LDA 2024-08-11 10:38:36 +02:00
commit b4cfd679ee

View file

@ -245,28 +245,31 @@ ParseeMessageHandler(ParseeData *data, HashMap *event)
bool direct = false; bool direct = false;
chat_id = ParseeGetFromRoomID(data, id);
ref = DbLock(data->db, 3, "rooms", id, "data");
json = DbJson(ref);
direct = JsonValueAsBoolean(HashMapGet(json, "is_direct"));
if (ParseeIsPuppet(data->config, m_sender) || if (ParseeIsPuppet(data->config, m_sender) ||
ParseeManageBan(data, m_sender, id)) ParseeManageBan(data, m_sender, id))
{ {
DbUnlock(data->db, ref);
Free(chat_id);
Free(reply_id); Free(reply_id);
Free(xepd); Free(xepd);
Free(unedited_id); Free(unedited_id);
return; return;
} }
chat_id = ParseeGetFromRoomID(data, id);
/* TODO: This ref should be marked as read-only,
* as LMDB doesn't seem to like having two concurrent RW
* transactions running. */
ref = DbLock(data->db, 3, "rooms", id, "data");
json = JsonDuplicate(DbJson(ref));
direct = JsonValueAsBoolean(HashMapGet(json, "is_direct"));
DbUnlock(data->db, ref);
ref = NULL;
if (!direct && !chat_id) if (!direct && !chat_id)
{ {
ParseeBotHandler(data, event); ParseeBotHandler(data, event);
DbUnlock(data->db, ref); JsonFree(json);
Free(chat_id); Free(chat_id);
Free(reply_id); Free(reply_id);
Free(xepd); Free(xepd);
@ -362,7 +365,7 @@ end:
Free(unauth); Free(unauth);
Free(unedited_id); Free(unedited_id);
DbUnlock(data->db, ref); JsonFree(json);
} }
void void