gin bug

客户端两个接口同时访问 ginweb 打印得知两个接口的context一样 抓包得知第二个接口的返回包含了第一个接口的返回值 第一个接口返回code 200 body 空 抓包显示 还是两个tcp连接 竟然出现这种问题

偶现

8:2 正常 vs 不正常 概率还挺高

确实是gin 的bug

// ServeHTTP conforms to the http.Handler interface.
func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
    c := engine.pool.Get().(*Context)
    c.writermem.reset(w)
    c.Request = req
    c.reset()

    engine.handleHTTPRequest(c)

    engine.pool.Put(c)
}

// HandleContext re-enter a context that has been rewritten.
// This can be done by setting c.Request.URL.Path to your new target.
// Disclaimer: You can loop yourself to death with this, use wisely.
func (engine *Engine) HandleContext(c *Context) {
    c.reset()
    engine.handleHTTPRequest(c)
    engine.pool.Put(c)
}



v1.6.3 修复的gin源码

// HandleContext re-enter a context that has been rewritten.
// This can be done by setting c.Request.URL.Path to your new target.
// Disclaimer: You can loop yourself to death with this, use wisely.
func (engine *Engine) HandleContext(c *Context) {
    oldIndexValue := c.index
    c.reset()
    engine.handleHTTPRequest(c)

    c.index = oldIndexValue
}

您可以自由的转载和修改,但请务必注明文章来源并且不可用于商业目的。
本站大部分内容收集于互联网,如果有侵权内容、不妥之处,请联系删除。敬请谅解!

  关于博主【WANG-FEiHU】

Replicate
-----------Complicate
--------------------------Appreciate
----------------------------------------[Fate]
-----------------------------------------------Elevate

三人行 有吾师

-------------花有重开日 梦无止境时-------------

  分类目录

  monitor(TD)

青春就是用来追忆的,当你怀揣着它时,它一文不值,只有将它耗尽后,再回过头看,一切才有了意义,爱过我们的人和伤害过我们的人,都是我们青春存在的意义。

在这有限的时间里,我们应该珍惜生命,珍惜机会,更要珍惜那得之不易的时间。因那滴答做响的时间脚步,一旦走过,再不回头。

要打败任何事情得先学会打败自己。

我会把每一次改变当做成长,哪怕是痛也值得。

时无英雄,使竖子成名

少年不识愁滋味,爱上层楼。爱上层楼。为赋新词强说愁。而今识尽愁滋味,欲说还休。欲说还休。却道天凉好个秋。