When saving a shared dict zone with timeout=, expired entries are
skipped. A comma is appended whenever another tree node follows a live
entry, even if all remaining nodes are expired. This can leave a
trailing comma in the state file, making it invalid JSON.
Insert commas before live entries only when a previous entry has been
rendered, so skipped entries do not affect the separators.
{
u_char *p, *dst;
size_t len;
+ ngx_uint_t first;
ngx_msec_t now;
ngx_time_t *tp;
ngx_rbtree_t *rbtree;
return NGX_OK;
}
+ first = 1;
+
for (rn = ngx_rbtree_min(rbtree->root, rbtree->sentinel);
rn != NULL;
rn = next)
continue;
}
+ if (!first) {
+ njs_chb_append_literal(chain, ",");
+ }
+
+ first = 0;
+
if (ngx_js_render_string(chain, &node->sn.str) != NGX_OK) {
return NGX_ERROR;
}
}
njs_chb_append_literal(chain, "}");
-
- if (next != NULL) {
- njs_chb_append_literal(chain, ",");
- }
}
njs_chb_append_literal(chain, "}");