echo
echo copied to clipboard
Handler gets called Multiple Times
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.
- You should check browser network tab if there are multiple calls to that path
- You should configure debugger for your IDE and debug that handler. Some guides for popular IDEs Goland and Visual Studio Code
- 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.
learning how to debug - line by line, could be your most significant "level up" in development career