Closed Alexfilus closed 3 years ago
looks like it falls down after 100-200 requests. Every time numbers are different.
Little update: error reproduced only with concurrent request handling. wrk -t 1 -c 2 http://127.0.0.1/ - got panic index of range, and that index always larger than content size wrk -t 1 -c 1 http://127.0.0.1/ - no panic, everything works
That looks like a race condition, can you please check if this goes away when you copy the input buffer before passing to the minifier? E.g.:
buf2 := &bytes.Buffer{}
io.Copy(buf2, buf)
err = m.Minify("text/html", c, buf2)
// ...
Additionally, can you check what happens if you run it with the race condition detector enabled? E.g.: go install -race [...]
Now it's also panic, but in template render...
go install -race
worked about a minute but found nothing.
If you skip minifying, does it still happen? To me it sounds like you have a race condition elsewhere. The minify
library isn't using concurrency, but it does modify the input byte stream in-place and requires it to be untouched by others while minifying. If anything in your code is changing that input byte-slice or e.g. reusing it for another request, that may be the problem.
If this doesn't happen when you disable the minifier, could you please make a small piece of code that reproduces the error?
I made some experiments. Looks like it's Minify and Fiber's template/html are incompatible somehow. My code works with template/html and without minify, if I turn on them both, program panics. Also I tried standard go template/html with standard net/http server, and with fasthttp. It works fine. I change template executor to jet. Panic is gone now! I don't find particular reason why it happend, but now my app works fine. Thank you, for attention.
@Alexfilus Even got this to work with Fiber/Fasthttp?
Hi! I'm using github.com/tdewolff/minify/v2/html with https://docs.gofiber.io/ When I just refresh browser page manually, everything is fine, but when I tried to test app performance with wrk, I got panic:
Here is handler code:
len which triggers panic is different for every try, and looks like some of request works fine before app fails