Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
408 views
in Technique[技术] by (71.8m points)

go - Why the context.Request.Body would be dirty when many goroutine read and write the body

when using golang gin framework, the context.Request.Body would be nil if someone already read it in some place, such as

data, _ := ioutil.ReadAll(c.Request.Body)

so in my deal, I put the data into the body again after i read it, such as

data, _ := ioutil.ReadAll(c.Request.Body)
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(data))

however, when more than one goroutines read and put the body concurrency, the body would be dirty sometimes, for my instance, the json body would be truncated and my code finally failed to decode the json string

I will be approciate if someone could help me explain the reason, since I am not so good in the operation systems

question from:https://stackoverflow.com/questions/65840165/why-the-context-request-body-would-be-dirty-when-many-goroutine-read-and-write-t

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...