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

bugfix: Delete put(c) HandleContext #1579

Closed
wants to merge 1 commit into from
Closed

bugfix: Delete put(c) HandleContext #1579

wants to merge 1 commit into from

Conversation

deepdarkness
Copy link

@deepdarkness deepdarkness commented Sep 30, 2018

This method "engine.pool.Put(c)" may put c twice in pool, this is a bug may cause a request with no response and another response with more than one response body.

First put:

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)
}

Second put:

func (engine *Engine) HandleContext(c *Context) {
	c.reset()
	engine.handleHTTPRequest(c)
	engine.pool.Put(c)
}

It may cause series problem, can return confusion response to use, Next request may take a using Context to response. Request Log:

[2018-09-29 19:51:21] method[POST] statusCode[200] remoteIP[----] requestId[8f6bafbe-b9af-43b8-956f-eed0ecfbe1e4] costTime[67.052ms] path[/front/v1/get/execQuery] ReqBody[{"RequestId":"8f6bafbe-b9af-43b8-956f-eed0ecfbe1e4","SubAccountUin":"----","Uin":"----","epoch":"ms","orgId":"-----etjgxtuw","query":"SELECT mean(\"free\") \n    FROM \"disk\"\n    WHERE time \u003e now() - 1h AND \"insId\" = 'IP_----'\n    GROUP BY time(5m)"}] RespBody[]

[2018-09-29 19:51:21] method[POST] statusCode[200] remoteIP[----] requestId[764b89a1-bc0b-4573-b625-40950baace32] costTime[49.432ms] path[/front/v1/get/execQuery] ReqBody[{"epoch":"ms","orgId":"-----etjgxtuw","query":"SELECT mean(\"used\") \n    FROM \"disk\"\n    WHERE time \u003e now() - 1h AND \"insId\" = 'IP_----'\n    GROUP BY time(5m)"}] RespBody[{"Response":{"RequestId":"764b89a1-bc0b-4573-b625-40950baace32","ResponseBody":"{\"results\":[{\"statement_id\":0,\"series\":[{\"name\":\"disk\",\"columns\":[\"time\",\"mean\"],\"values\":[[1538218200000,13094400],[1538218500000,13094400],[1538218800000,13094400],[1538219100000,13094400],[1538219400000,13094400],[1538219700000,13094400],[1538220000000,13094400],[1538220300000,13094400],[1538220600000,13094400],[1538220900000,13094400],[1538221200000,13094400],[1538221500000,13094400],[1538221800000,13094400]]}]}]}\n"}}{"Response":{"RequestId":"764b89a1-bc0b-4573-b625-40950baace32","ResponseBody":"{\"results\":[{\"statement_id\":0,\"series\":[{\"name\":\"disk\",\"columns\":[\"time\",\"mean\"],\"values\":[[1538218200000,196057271734.85715],[1538218500000,196057202688],[1538218800000,196057109435.73334],[1538219100000,196057034296.8889],[1538219400000,196056924433.06668],[1538219700000,196056770833.06668],[1538220000000,196056610816],[1538220300000,196056530807.46667],[1538220600000,196056445424.48486],[1538220900000,196056361398.85715],[1538221200000,196056234448.21335],[1538221500000,196056150971.73334],[1538221800000,196056091891.8095]]}]}]}\n"}}{"Response":{"RequestId":"764b89a1-bc0b-4573-b625-40950baace32","ResponseBody":"{\"results\":[{\"statement_id\":0,\"series\":[{\"name\":\"disk\",\"columns\":[\"time\",\"mean\"],\"values\":[[1538218200000,4435639539.809524],[1538218500000,4435708586.666667],[1538218800000,4435801838.933333],[1538219100000,4435876977.777778],[1538219400000,4435986841.6],[1538219700000,4436140441.6],[1538220000000,4436300458.666667],[1538220300000,4436380467.2],[1538220600000,4436465850.181818],[1538220900000,4436549875.809524],[1538221200000,4436676826.453333],[1538221500000,4436760302.933333],[1538221800000,4436819382.857142]]}]}]}\n"}}]

There is two ResponseBody in second resp but empty ResponseBody in first query. like second req stole from first req.

This method "engine.pool.Put(c)" may put c twice in pool, this is a bug may cause a request with no response and another response with more than one response body.
@codecov
Copy link

codecov bot commented Sep 30, 2018

Codecov Report

Merging #1579 into master will increase coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1579      +/-   ##
==========================================
+ Coverage   99.06%   99.11%   +0.05%     
==========================================
  Files          39       39              
  Lines        1929     1928       -1     
==========================================
  Hits         1911     1911              
+ Misses         14       13       -1     
  Partials        4        4
Impacted Files Coverage Δ
gin.go 98.53% <ø> (+0.47%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 91a4459...1a0a349. Read the comment docs.

@thinkerou
Copy link
Member

@deepdarkness please #1565 thanks your commit.

@appleboy
Copy link
Member

appleboy commented Oct 1, 2018

#1565 merged.

@appleboy appleboy closed this Oct 1, 2018
@deepdarkness deepdarkness deleted the patch-1 branch October 10, 2018 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants