BUG/MINOR: stats-file: manipulate shm-stats-file heartbeat using unsigned int

shm-stats-file heartbeat is derived from now_ms with an extra time added
to it, thus it should be handled using the same time as now_ms is.

Until now, we used to handle heartbeat using signed integer. This was not
found to cause severe harm but it could result in improper handling due
to early wrapping because of signedness for instance, so let's better fix
that before it becomes a real issue.

It should be backported in 3.3
This commit is contained in:
Aurelien DARRAGON 2026-02-19 14:59:52 +01:00
parent 04a4d242c9
commit 2b7849fd02
2 changed files with 4 additions and 4 deletions

View File

@ -47,7 +47,7 @@ struct shm_stats_file_hdr {
*/
struct {
pid_t pid;
int heartbeat; // last activity of this process + heartbeat timeout, in ticks
uint heartbeat; // last activity of this process + heartbeat timeout, in ticks
} slots[64];
int objects; /* actual number of objects stored in the shm */
int objects_slots; /* total available objects slots unless map is resized */

View File

@ -492,7 +492,7 @@ static int shm_stats_file_check_ver(struct shm_stats_file_hdr *hdr)
return 1;
}
static inline int shm_hb_is_stale(int hb)
static inline int shm_hb_is_stale(uint hb)
{
return (hb == TICK_ETERNITY || tick_is_expired(hb, now_ms));
}
@ -501,7 +501,7 @@ static inline int shm_hb_is_stale(int hb)
*/
static int shm_stats_file_slot_isfree(struct shm_stats_file_hdr *hdr, int id)
{
int hb;
uint hb;
hb = HA_ATOMIC_LOAD(&hdr->slots[id].heartbeat);
return shm_hb_is_stale(hb);
@ -513,7 +513,7 @@ static int shm_stats_file_slot_isfree(struct shm_stats_file_hdr *hdr, int id)
int shm_stats_file_get_free_slot(struct shm_stats_file_hdr *hdr)
{
int it = 0;
int hb;
uint hb;
while (it < sizeof(hdr->slots) / sizeof(hdr->slots[0])) {
hb = HA_ATOMIC_LOAD(&hdr->slots[it].heartbeat);