gofiber/template

๐Ÿ› [Bug]: request fail before the template is available

iacore opened this issue ยท 5 comments

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:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

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

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.

@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 #330

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?

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