Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handler gets called Multiple Times #2474

Open
DawnKosmos opened this issue Jul 6, 2023 · 2 comments
Open

Handler gets called Multiple Times #2474

DawnKosmos opened this issue Jul 6, 2023 · 2 comments

Comments

@DawnKosmos
Copy link

DawnKosmos commented Jul 6, 2023

Issue Description

Under specific conditions and wrong html header, a routes is executed multiple times

Checklist

  • [ Y] Dependencies installed
  • [ Y] No typos
  • [ Y] Searched existing issues and docs

Expected behaviour

Handler should be called once

Actual behaviour

Handler gets Called once, then another 3 times within microseconds?

Steps to reproduce

I have no idea, why. The Code Explains some debugging atempts
Tested with Chrome and Firefox

Working code to debug

e.GET("/test/:uid", db.TestAlertGet, db.Auth) // Has a Bug
e.GET("/hello", db.TestAlertGet, db.Auth) // (For test) Same Handler on another route Has no bug!!!
// I also disabled all other handler to see if I still have that confilct.

// The problem function
func (p *Pgx) TestAlertGet(c echo.Context) error {
	uid := "404b1175-60c6-4c34-99f4-2371045bb1a1"  //c.Param("uid") changed to Static to see if c.Param causing the bug.
	userId := c.Get("ID").(int64)
	res, err := p.q.GetApiFromWebhookId(ctx, qq.GetApiFromWebhookIdParams{
		WebhookID: uid,
		UserID:    userId,
	})
	if err != nil {
		log.Println(err)
	}

// I only get the Bug when I render a Template!
	err = c.Render(200, "alert_test.html", TemplateData[qq.GetApiFromWebhookIdRow]{
		Title: "Test",
		Error: "",
		Data:  res,
	})
	if err != nil {
		log.Println(err)
	}
	return err
}

Edit: The Function gets called for every .css file I locally serve. Removing them fixes the multiple Calls .

Edit2: Fixed it

I included the stylsheets wrong
    <link rel="stylesheet" href="main.css">   | false gets the error
    <link rel="stylesheet" href="/main.css">  | correct no bugs anymore

But still I am confused why under some conditions a fault in my HTML Header leads to the function being called multiple times.

@aldas
Copy link
Contributor

aldas commented Jul 6, 2023

  1. You should check browser network tab if there are multiple calls to that path
  2. You should configure debugger for your IDE and debug that handler. Some guides for popular IDEs Goland and Visual Studio Code
  3. Something I noticed. your first block:
	if err != nil {
		log.Println(err)
	}

should return err otherwise you will call render even for GetApiFromWebhookId errors.

other than that - issue does not have enough information to say why it is called.

@aldas
Copy link
Contributor

aldas commented Jul 6, 2023

learning how to debug - line by line, could be your most significant "level up" in development career

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants