fiber: πŸ› template/html: Cannot Clone "layouts/main" after it has executed

Fiber version

v2.0.2

Issue description

Continue from https://github.com/gofiber/fiber/issues/814, which were having the problem of

html/template: cannot Clone "layouts/main" after it has executed

  • it seems only occurs to html/template, and
  • the solution was to reload the template engine.

However, the reload was not necessary before, and it only works for simple demo examples. I.e., my demo is working after the fix, while my real application is still suffering from the issue.

Here are the details:

Code snippet

package main

import "github.com/gofiber/fiber/v2"

func main() {
  app := fiber.New()

  // Steps to reproduce
	app.Get("/layout", func(c *fiber.Ctx) error {
		// Render index within layouts/main
		return c.Render("index", fiber.Map{
			"Title": "Hello, World!",
		}, "layouts/main")
	})

  log.Fatal(app.Listen(":3000"))
}

I’ve setup a new demo at https://gitlab.com/suntong/template-html/,

  • everything about the html template handing is the same as my real application, and even the middlewares
  • the only thing I see different from the two is there are more business logic in my real application
  • yet my real application can render the html template only once, then it get to the same error again, while the above published demo can sustain the repeated requests.

Here are the test logs:

$ cat go.mod 
module template-html

go 1.14

require (
        github.com/gofiber/fiber/v2 v2.0.2
        github.com/gofiber/template v1.6.2
)

# Start my real application

$ curl http://localhost:5858/layout
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  
  <link href="https://fonts.googleapis.com/css?family=Montserrat:400,500|Poppins:400,500,600,700|Roboto:400,500"
  rel="stylesheet" />
  <link href="https://cdn.materialdesignicons.com/3.0.39/css/materialdesignicons.min.css" rel="stylesheet" />
  
  <link id="sleek-css" rel="stylesheet" href="assets/css/sleek.min.css" />

  <title>Hello, World! - </title>
</head>

<body id="body">

<h1>Hello, World!</h1>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="assets/plugins/slimscrollbar/jquery.slimscroll.min.js"></script>
  <script src="assets/js/sleek.bundle.js"></script>
</body>

</html>

# Start my demo
$ curl http://localhost:3000/layout
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  
  <link href="https://fonts.googleapis.com/css?family=Montserrat:400,500|Poppins:400,500,600,700|Roboto:400,500"
  rel="stylesheet" />
  <link href="https://cdn.materialdesignicons.com/3.0.39/css/materialdesignicons.min.css" rel="stylesheet" />
  
  <link id="sleek-css" rel="stylesheet" href="assets/css/sleek.min.css" />

  <title>Hello, World! - </title>
</head>

<body id="body">

<h1>Hello, World!</h1>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="assets/plugins/slimscrollbar/jquery.slimscroll.min.js"></script>
  <script src="assets/js/sleek.bundle.js"></script>
</body>

</html>

# repeat
$ curl http://localhost:5858/layout
html/template: cannot Clone "layouts/main" after it has executed

$ curl -s http://localhost:3000/layout | tail -6
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="assets/plugins/slimscrollbar/jquery.slimscroll.min.js"></script>
  <script src="assets/js/sleek.bundle.js"></script>
</body>

</html>

. . .

$ curl -s http://localhost:3000/layout | tail -6
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="assets/plugins/slimscrollbar/jquery.slimscroll.min.js"></script>
  <script src="assets/js/sleek.bundle.js"></script>
</body>

</html>

i.e., my demo can sustain the repeated requests while my real application cannot.

Again, everything about the html template handing is the same between my demo and my real application, and even the middlewares. So I’m suspecting that any other mildly complicated template/html based application would suffer from the same issue, caused by the same problem that needs to reload the template engine. If someone has to have my real application to duplicate the issue, please give me your gitlab id so that I can add you to my private project.

Thanks

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

@suntong, @anton7r this problem is fixed in v1.6.3, feel free to re-open if you encounter problems πŸ‘

I have some time tomorrow to debug this issue, I will post updates here πŸ‘

i think removing this from the golang/go/html/template/template.go and refactoring the code would fix the issue kuva

im looking into it!