gofiber / template

🧬 Template engine middleware for Fiber
https://docs.gofiber.io/guide/templates
MIT License
262 stars 52 forks source link

🐛 [Bug]: request fail before the template is available #339

Closed iacore closed 7 months ago

iacore commented 7 months ago

Bug Description

Observable behavior (recalled from my memory):

/layout template not found

How to Reproduce

I don't know! I only saw it once.

the actual application in question is https://codeberg.org/vnpower/pixivfe where i

  1. go run .
  2. visit http//localhost:8282/ in browser

I couldn't get it to reproduce again.

I suspect this is a race condition

Expected Behavior

The server should not respond to requests if the templates are not compiled yet.

Fiber Version

v2.52.0

Code Snippet (optional)

No response

Checklist:

welcome[bot] commented 7 months ago

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

iacore commented 7 months ago

I think I found the problem. there is no mutex

search for the following code snippet in github.com/gofiber/template

    if !e.Loaded || e.ShouldReload {
        if e.ShouldReload {
            e.Loaded = false
        }
        if err := e.Load(); err != nil {
            return err
        }
    }

if e.ShouldReload is true, then after e.Load() e.Loaded still could be false (if the surrounding function is called twice in quick succession.

gaby commented 7 months ago

@iacore We are aware of this issue. I have a PR to fix the issue on all the engines. Should be ready in the next few days. I found the issue 2-3 weeks ago while writing new Benchmarks.

Rel https://github.com/gofiber/template/pull/330

iacore commented 7 months ago

Thanks!

I also noticed that the Jet template engine doesn't output any error when the template is broken. It just... renders until the broken part, result in partially rendered page. Are you aware of this issue too?

gaby commented 7 months ago

@iacore Can you open a separate ticket for that issue. I can take a look.