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】

Duplicate
-----------Complicate
--------------------------Appreciate
----------------------------------------[Fate]
-----------------------------------------------Elevate

三人行 有吾师

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

  分类目录

  monitor(TD)

低头哭过别忘了抬头继续走。

不要被任何人打乱自的脚步,因为没有谁会像你一样清楚和在乎自己梦想。

你要记住你不是为别人而活,你是为自己而活。

我未曾跨过山河大海,也没穿过人山人海

停留在冬夜的冷风中,我不是也不想装脆弱,只因为你说过爱是等待,是细水长流