Skip to content

Commit

Permalink
Merge pull request #1872 from kamailio/cchance/htable_dmq_fix
Browse files Browse the repository at this point in the history
htable: fix infinite loop during dmq sync of large tables
  • Loading branch information
charlesrchance committed Feb 28, 2019
2 parents d726bd4 + a176ad4 commit 7702fba
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/modules/htable/ht_dmq.c
Expand Up @@ -139,36 +139,43 @@ static int ht_dmq_cell_group_flush(dmq_node_t* node) {

srjson_doc_t *jdoc = &ht_dmq_jdoc_cell_group.jdoc;
srjson_t *jdoc_cells = ht_dmq_jdoc_cell_group.jdoc_cells;
int ret = 0;

srjson_AddItemToObject(jdoc, jdoc->root, "cells", jdoc_cells);

LM_DBG("json[%s]\n", srjson_PrintUnformatted(jdoc, jdoc->root));
LM_DBG("jdoc size[%d]\n", ht_dmq_jdoc_cell_group.size);
jdoc->buf.s = srjson_PrintUnformatted(jdoc, jdoc->root);
if(jdoc->buf.s==NULL) {
LM_ERR("unable to serialize data\n");
return -1;
ret = -1;
goto cleanup;
}
jdoc->buf.len = strlen(jdoc->buf.s);

LM_DBG("sending serialized data %.*s\n", jdoc->buf.len, jdoc->buf.s);
if (ht_dmq_send(&jdoc->buf, node)!=0) {
LM_ERR("unable to send data\n");
return -1;
ret = -1;
}

LM_DBG("jdoc size[%d]\n", ht_dmq_jdoc_cell_group.size);
cleanup:

srjson_DeleteItemFromObject(jdoc, jdoc->root, "cells");
ht_dmq_jdoc_cell_group.count = 0;
ht_dmq_jdoc_cell_group.size = dmq_cell_group_empty_size;

if(jdoc->buf.s!=NULL) {
jdoc->free_fn(jdoc->buf.s);
jdoc->buf.s = NULL;
}

srjson_Delete(jdoc, jdoc_cells);
ht_dmq_jdoc_cell_group.jdoc_cells = srjson_CreateArray(&ht_dmq_jdoc_cell_group.jdoc);
if (ht_dmq_jdoc_cell_group.jdoc_cells==NULL) {
LM_ERR("cannot re-create json cells array! \n");
return -1;
ret = -1;
}

ht_dmq_jdoc_cell_group.count = 0;
ht_dmq_jdoc_cell_group.size = dmq_cell_group_empty_size;

return 0;
return ret;
}

static void ht_dmq_cell_group_destroy() {
Expand Down

0 comments on commit 7702fba

Please sign in to comment.