You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The currently experimental shm-stats-file directive causes the stats file to grow on every reload when a backend has two server GUIDs like this:
server s1 127.0.0.1:1 guid srv:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:SRV_1 disabled server s10 127.0.0.1:1 guid srv:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:SRV_10 disabled
First is 126 chars
Second is 127 chars
First is prefix of second
haproxy seems to truncate the 127th character when persisting the GUID to the shm stats file causing a duplication of the first GUID on every reload. This does not cause an error until the shm-stats-file-max-objects is reached.
Expected Behavior
haproxy should not truncate the last character of GUIDs when persiusting into the stats file.
Steps to Reproduce the Behavior
Take the haproxy.cfg from further below and run this script:
rm -f /dev/shm/haproxy-test
haproxy -f haproxy.cfg -W -db &
sleep 2
# dump object count: expect 5 (4 unique + 1 truncation duplicate)
od -A n -t d4 -j 536 -N 4 /dev/shm/haproxy-test
# each reload adds one duplicate objectforiin$(seq 1 10);dokill -USR2 $!; sleep 0.3;done
sleep 2
# expect 15 (4 unique + 11 duplicates)
od -A n -t d4 -j 536 -N 4 /dev/shm/haproxy-test
kill$!
Do you have any idea what may have caused this?
I am no C expert, but it seems that counters.c:112 truncates GUIDs written to the SHM stats file:
Indeed your analysis is correct: shm_obj->guid can store GUID_MAX_LEN + 1 (1 extra byte for the terminating NULL byte that is added by snprintf() automatically), the - 1 was added by mistake, I couldn't recall that snprintf() doesn't write past the number of bytes specified to append the terminating NULL byte, so this is not needed indeed, and as you pointed out it causes unexpected behavior because we don't support the full 128 characters while the GUID API supports it.
Your proposal looks correct to me :)
Would you like to provide the patch yourself or do you want us to do that for you?
Thank you very much for all the details and the problem analysis
Thank you for getting back to me so quickly @Darlelet!
Would you like to provide the patch yourself or do you want us to do that for you?
I know you do the whole mailing list + diff file thing from the olden times. I am not really used to it. Before I fumble around with that process I would be happy if you just did it 😃
Oh maybe one more remark: New haproxy processes loaded the shm file with the duplicate entries without question. Maybe some additional input validation would be helpful in case similar issues come up in the future. When validation fails haproxy could discard the file and log a warning.
Hmm, I understand but in fact GUID duplicates are intended in the shm-stats-file, because upon config change one can decide to reuse the same GUID for a different object type, while existing (older) processes still refer to the old one.
Once the old object (with duplicated GUID) is not used anymore the slot will be automatically reused, but indeed in your case it would tend to pile up when reloading often
Also, for performance reason, when a new process start, it picks the first object matching the GUID and expected object type, it doesn't try to scan the full file if not needed
Sorry for jumping to an adjacent topic, but I wanted to ask before creating a feature request: In my case I only generated GUIDs because I wanted continuous Prometheus metrics without having ghost traffic loss in the graphs. So I do not really care about the GUIDs themselves. I just set them to use the shm file. Could they be autogenerated somehow? I currently use some generic schema like <type>:<name> e.g. be:my_backend. Can we have this autogenerated if not set?
Regarding the initial issue it is now fixed in master, and will soon be backported to 3.3
For your last question, although I understand your need I don't have answers to provide for now as I thought the current GUID design was intentional so I'll let other speak for themselves if they have relevant insights
Activity
Darlelet commentedon Apr 3, 2026
Thanks for the report @phihos, I will take a look shortly :)
Darlelet commentedon Apr 3, 2026
Indeed your analysis is correct:
shm_obj->guidcan store GUID_MAX_LEN + 1 (1 extra byte for the terminating NULL byte that is added by snprintf() automatically), the- 1was added by mistake, I couldn't recall that snprintf() doesn't write past the number of bytes specified to append the terminating NULL byte, so this is not needed indeed, and as you pointed out it causes unexpected behavior because we don't support the full 128 characters while the GUID API supports it.Your proposal looks correct to me :)
Would you like to provide the patch yourself or do you want us to do that for you?
Thank you very much for all the details and the problem analysis
phihos commentedon Apr 3, 2026
Thank you for getting back to me so quickly @Darlelet!
I know you do the whole mailing list + diff file thing from the olden times. I am not really used to it. Before I fumble around with that process I would be happy if you just did it 😃
phihos commentedon Apr 3, 2026
Oh maybe one more remark: New haproxy processes loaded the shm file with the duplicate entries without question. Maybe some additional input validation would be helpful in case similar issues come up in the future. When validation fails haproxy could discard the file and log a warning.
Darlelet commentedon Apr 3, 2026
You're welcome, no worries I can write the patch and credit you if that sounds good for you
Darlelet commentedon Apr 3, 2026
Hmm, I understand but in fact GUID duplicates are intended in the shm-stats-file, because upon config change one can decide to reuse the same GUID for a different object type, while existing (older) processes still refer to the old one.
Once the old object (with duplicated GUID) is not used anymore the slot will be automatically reused, but indeed in your case it would tend to pile up when reloading often
Darlelet commentedon Apr 3, 2026
Also, for performance reason, when a new process start, it picks the first object matching the GUID and expected object type, it doesn't try to scan the full file if not needed
phihos commentedon Apr 3, 2026
I see. Then there is not much we can do I guess.
Sorry for jumping to an adjacent topic, but I wanted to ask before creating a feature request: In my case I only generated GUIDs because I wanted continuous Prometheus metrics without having ghost traffic loss in the graphs. So I do not really care about the GUIDs themselves. I just set them to use the shm file. Could they be autogenerated somehow? I currently use some generic schema like
<type>:<name>e.g. be:my_backend. Can we have this autogenerated if not set?BUG/MINOR: counters: fix unexpected 127 char GUID truncation for shm-…
Darlelet commentedon Apr 4, 2026
Regarding the initial issue it is now fixed in master, and will soon be backported to 3.3
For your last question, although I understand your need I don't have answers to provide for now as I thought the current GUID design was intentional so I'll let other speak for themselves if they have relevant insights
BUG/MINOR: counters: fix unexpected 127 char GUID truncation for shm-…