Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Just how are you modifying strings? Cause that's your bug to fix.


That was probably done by fiber[1] the code specifically took the param from it in the function passed to the Get(path string, handlers ...Handler) Router function. c is the *fiber.Ctx passed by fiber to the handler. My code took the string from c.Param("name") passed it to url.QueryUnescape then another function which had a mutex around setting the key/value in the map. I got the hint it was slices and something modifying the keys when I found truncated keys in the key list.

My guess is fiber used the same string for the param to avoid allocations. The fix for it is just to create a copy of the string with strings.Clone() to ensure it does not get mutated when it is used as a key. I understand it was an issue with my code, it just wasn't something I expected to be the case so it took several hours and using the debugger to find the root cause. Probably didn't help that a lot of the code was generated by Grok-4-Code/Sonic as a vibe coding test when I decided to go back a few months later and try and fix some of the issues I had myself.

[1] https://github.com/gofiber/fiber


Go strings are supposed to be immutable.

I see that fiber goes behind your back and produces potentially mutable strings behind your back: https://github.com/gofiber/utils/blob/c338034/convert.go#L18

And… I actually don't have an issue with it to be honest. I've done the same myself.

But this mutability should never escape. I'd never persist in using a library that would let it escape. But apparently… it's intentional: https://github.com/gofiber/fiber/issues/185

Oh well. You get what you ask for. Please don't complain about maps if you're using a broken library.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: