Skip to content

Commit

Permalink
Re-seed PRNG if lwan_random_uint64() returns 0 when getting req id
Browse files Browse the repository at this point in the history
  • Loading branch information
lpereira committed May 16, 2024
1 parent b4f8966 commit bcf9dbc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib/lwan-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static void lwan_random_seed_prng_for_thread(const struct lwan_thread *t)

uint64_t lwan_random_uint64()
{
static uint64_t value;
static uint64_t value = 1;

return ATOMIC_INC(value);
}
Expand Down Expand Up @@ -142,9 +142,15 @@ uint64_t lwan_request_get_id(struct lwan_request *request)
{
struct lwan_request_parser_helper *helper = request->helper;

if (helper->request_id == 0)
if (helper->request_id == 0) {
helper->request_id = lwan_random_uint64();

if (UNLIKELY(helper->request_id == 0)) {
lwan_random_seed_prng_for_thread(request->conn->thread);
return lwan_request_get_id(request);
}
}

return helper->request_id;
}

Expand Down

0 comments on commit bcf9dbc

Please sign in to comment.